2 C Program Structure
2 C Program Structure
2 C Program Structure
Prepared By:
G. J. Kamani
C Program Structure
Link Section
#include <stdio.h>
void main()
{ main( ) Function Section
printf(“Welcome To CAET-Godhra”);
}
C Character Set
Alphabets : A, a, B, b, C, c etc….
Numbers : 1,2,3etc…
Special Symbols : , (Comma), ;(Semi colon), # (Hash), =(equal) etc…
White Space : Blank Space, Horizontal Tab, New Line etc…
C Constant
Constants in C refer to fixed values that do not change during the execution of a
program. C language constants are also known as Literals. C supports several
types of constants as under.
NUMERIC CONSTANT:
Integer Constant=> 11, 22, -400, +323, 0, 99 etc…
Real Constant => 12.32, -23.465, 0.50 etc…
CHARACTER CONSTANT:
Single Character Constant => ‘a’, ‘A’, ‘5’, ‘$’ etc…
String Constant => “Hello”, “5+3” etc…
C Keywords
Signed Unsigned
A variable is a data name that may be used to store a data value. A variable may take
different values at different times during execution.
A variable name can be chosen by the programmer in a meaningful way.
The printf function is just a useful function from the standard library(stdio.h) of
functions that are accessible by C programs.
#include <stdio.h>
void main()
{
int a;
float b;
a=100;
b=10.5628;
Output
printf("%d \n",a); 1 0 0
printf("%5d \n",a); 1 0 0
printf("%-5d \n",a); 1 0 0
1 0 . 5 6 2 8
printf("%f \n",b);
printf("%.2f \n",b); 1 0 . 5 6
printf("%10.3f \n",b); 1 0 . 5 6 3
printf("%-10.3f \n",b); 1 0 . 5 6 3
printf(“%c \n”,’A’); A
printf(“%c \n”,65);
A
}
printf() function Program 2
#include <stdio.h>
void main()
Output
{
F F
printf("Hexadecimal: %x\n", 255);
3 7 7
printf("Octal: %o\n", 255);
1 5 0
printf("Unsigned value: %u\n", 150);
6 5 5 2 6
printf("Unsigned value: %u\n", -10);
H E L L 0
printf("%s\n", "HELLO");
H E L L O
printf(“%10s\n", " HELLO");
H E L L O
printf(“%-10s\n", " HELLO");
H E L
printf(“%.3s\n", " HELLO");
H E L
printf(“%10.3s\n", " HELLO");
}
Thank You