Professional Documents
Culture Documents
Intro 2
Intro 2
executable statements;
}
user defined functions
Akshata Angadi, Assistant Professor, CSE Dept., GIT
• The Documentation Section
• consists of a set of comment lines giving the name of the program and other
details.
• The Link Section
• provides instructions to the compiler to link functions from the system library.
• The Definition Section
• defines all symbolic constants.
• The Global Declaration Section:
• Variables are declared outside the function so that it is easily accessible to all
other functions defined in a program.
• main() function:
• Every C program must have one main function section. This section contains
two parts, declaration and executable part.
• It is an entry point of all program.
Akshata Angadi, Assistant Professor, CSE Dept., GIT
Main() consists of 2 parts :-
• Declaration Part
• declares all the variables used in the executable part.
• Execution Part
• There should be at least one statement in the executable part which
contains instructions to perform certain task.
• The declaration and executable part must appear between the
opening and closing braces.
• All statements in the declaration part should end with the semicolon.
Identifiers
• Refers to names given to the variables, functions and arrays.
Rules :
• Keywords cannot be used as Identifiers
• Case sensitive
• First character should be alphabet or underscore.
• Must consist of only letters, digits or underscore.
• Must not contain white space
Akshata Angadi, Assistant Professor, CSE Dept., GIT
Constants :
• Constants -> fixed values
• The values will not be changed during execution of program
• Can define using const word or using symbolic constants
Strings :
• Sequence of Characters is said to be Strings.
• Character is written in single quote where as Strings are placed
in double quotes.
Float Types
Type Storage size Value range (16-bit machine) Precision
float 4 byte 3.4E-38 to 3.4E+38 6 decimal places
C is case-sensitive.
Example (Valid):
Salary_Employee, var1, var_2, _v3 , _V3 , sum
(Invalid)
^sal, dfg), #var1 , 1var3 , $sum
Akshata Angadi, Assistant Professor, CSE Dept., GIT
Variable Definition and Initialization
Variable Definition/Declaration
<datatype> var_list;
Variable Initialization
<datatype> var_name= var_value;
Eg:
int A,B,C; // variable definition
A=3; // variable initialization
B=4;
C=10;
Akshata Angadi, Assistant Professor, CSE Dept., GIT
Basic Data Types
Format
Type Description
Specifier
Typically a single octet(one byte). This is an character
char %c
type.
int The most natural size of integer for the machine. %d
i. scanf- Syntax:
scanf ( “ control string “ , &var1, &var2, --- &varn) ;
where
control string controls the format in which data is read.
&var1,&var2 addresses of variables
ii. printf-Syntax:
printf ( “ control string “ , var1, var2, --- varn) ;
where
control string controls the format in which data is displayed.
var1,var2 values of variables
Example:
Write a C Program to print Hello World.
// Program to print Hello World
#include<stdio.h> //Link Section
main( )
{
printf(“Hello World”) ; //Executable Statement
return 0 ;
} Akshata Angadi, Assistant Professor, CSE Dept., GIT
Sample Programs
• Write a program to print your Full Name (single line).
• Write a program to print your Mom Name twice.
• Write a Program to print your Home Address (multi line statement).
• Write a program to print : (PRINT ALL characters given below)
****”Hurray !!! My Team (India), WON the Match”.****