2. C_programming1
2. C_programming1
1
Structure of C Program
Preprocessor Commands
Main Function
Comment
Library Function
End of Program
2
Preprocessor Commands
These commands tells the compiler to do preprocessing before doing
actual compilation.
Like #include <stdio.h> is a preprocessor command which tells a C
compiler to include stdio.h file before going to actual compilation.
3
Functions
Functions are main building blocks of any C Program.
Every C Program will have one or more functions and there is one
mandatory function which is called main() function.
4
Comments
Comments are used to give additional useful information inside a C
Program.
All the comments will be put inside /*...*/ as given in the example above.
A comment can span through multiple lines.
6
Structure of C Program
Preprocessor Commands
Main Function
Comment
Library Function
End of Program
7
C’s Basic Data Type
Type Keyword format Memory
Specifier Requirements
Character data char %c 1 Byte
Signed whole numbers int %d 2 or 4 Byte
Floating-point numbers float %f 4 Byte
Double-precision floating- double %lf 8 Byte
point number
valueless void ---
8
How to Declare Variables
• To declare a variable, use this general form:
type var-name;
• In C, a variable declaration is a statement and
it must end in a semicolon (;).
9
Variable
• Variables consist of letters and digits, in any order, except that the
first character must be a letter.
• Both upper-and lowercase letters are permitted, though common
usage favors the use of lowercase letters for most types of variables.
• Upper- and lowercase letters are not interchangeable (i.e., an
uppercase letter is not equivalent to the corresponding lowercase
letter.)
10
Variable (cont.)
• The underscore character (_) can also be included, and is considered
to be a letter.
• An underscore is often used in the middle of an variable.
• A variable may also begin with an underscore, though this is rarely
done in practice.
11
Variable (cont.)
• Case-sensitive
• COUNT and count are not same
12
Variable (Cont.)
Can not Use blank space
Apon 1joty
joty-5
apon
apon123 this_is_a_long_name
_sojeb_1 VaReNdRa
14
Is it Valid Variable Name?
16
Keywords
• There are certain reserved words, called Keywords, that have
standard, predefined meaning in C
17
Keywords
18
Expressions
• An expression is a combination of operators and operands.
• C expressions follow the rule of algebra
Expression Operator
Arithmetic Expression +, -, *, /, %
Logical Expression AND, OR, NOT
Relational ==, !=, <, >, <=, >=
19
Assign value to variable
• To assign a value to a variable, put its name to the left of an equal sign (=).
• Put the variable you want to give the variable to the right of the equal sign.
variable value
;
20
21
Input Numbers From Keyboard
22
23
Escape Sequences
• There are certain characters in C when they are preceded by a
backslash (\) they will have special meaning.
• They are used to represent like newline (\n) or tab (\t).
24
Escape Sequences
25
Defining Constants
• There are two simple ways in C to define constants:
• Using #define preprocessor.
• Using const keyword.
26
Using #define preprocessor
• Following is the form to use #define preprocessor to define a
constant:
27
Using #define preprocessor
28
Symbolic Constants
30
31