Types of C Variables:: The Following Are Some Types of C Variables On The Basis of Constants Values It Has
Types of C Variables:: The Following Are Some Types of C Variables On The Basis of Constants Values It Has
1
Rules for Constructing Variable
Names:
A variable name may consist of letters,
digits, and the underscore ( _ )
The first character of variable name may
be an alphabetic character or an
underscore ( _ )
The first character of variable name
cannot be a digit.
Blank spaces are not allowed in a
variable name.
3
C keywords:
Keywords are the words whose meaning
has already been explained to the C
compiler.
The keywords are also called as
‘Reserved words’.
Keywords cannot be used as variable
names.
There are 32 keywords known to C.
5
The first C program:
For example:
write a program to add two numbers.
6
#include<stdio.h>
#include<conio.h>
Void main ()
Int a;
Int b;
Int s;
Printf(“enter value for a \n”);
Scanf(“%d”,&a);
Printf(“enter value for b:\n”);
7
Scarf(“%d”,&b);
S=a+b;
printf(“in sum :%d”,s);
getch ()
}
8
Compilation and execution of C
program:
To type your C program you need another program
called Editor.
once the program has been typed it needs to be
converted to machine language (0s and 1s) before
the machine can execute it. To carry out this
conversion we need another program called
Compiler.
Integrated development environment (IDE):
consists of an Editor as well as the compiler.
E.g. Turbo C++, Microsoft C++ and Borland C+
+
9
Receiving Input :
○ Printf( );
printf( )outputs the values to the screen whereas
scanf( ) receives them from the keyboard.
○ Scanf( );
To make the program general the program Itself
should ask the user to supply the values at run time.
This can be achieved using a function called scanf( )
This function is a counter-part of the printf( ) function.
10
C instructions
There are basically three types of
instructions in C:
Type Declaration Instruction
Arithmetic Instruction
Control Instruction
11
Type Declaration Instruction
This instruction is used to declare the type
of variables being used in the program.
Any variable used in the program must be
declared before using it in any statement.
The type declaration statement is written at
the beginning of main( ) function.
Ex: int add ;
float ave, per ;
char name, code ;
There are several variations of the type
declaration instruction. These are discussed
below:
While declaring the type of variable we can also
initialize it as shown below.
○ int i = 10, j = 25 ;
○ float a = 1.5, b = 1.99 + 2.4 * 1.44 ;
3rd = Assignment