Professional Documents
Culture Documents
• INT
INT SUM = 10
FUNCTION
DATATYPE VALUE
NAME
APPLICATIONS:-
• Operating System.
• Assemblers.
• Language Compilers.
• Text Editors.
• Network Drivers.
• Print Spoolers.
• Language Interpreters.
• DataBases.
• Modern Programs.
• Utilities.
STRUCTURE OF C PROGRAM:-
• Documentation Section.
• Link Section.
• Definition Section.
• User Defined Section.
• Main Function.
• Global Declaration Section.
STRUCTURE WITH EXPLANATION:-
• DOCUMENTATION SECTION:- (Name, Place, Address, etc..).
• LINK SECTION:- (Integer, Float, Character, String, Double, etc..).
• DEFINITION SECTION:- (#, ;, (), [], “”, etc..).
• USER DEFINED SECTION:- (Scanf).
• MAIN FUNCTION:- (Int main/ Void main).
• GLOBAL DECLARATION SECTION:- (Declaring one or more function in same program).
• E.G:-{
int sum{
}
int add{
}
}
EXAMPLE OF C PROGRAM
ACCORDING TO STRUCTURE:-
#include<stdio.h>
Int main()
{
printf(“Hello World…!!!”);
Return 0;
}
EXPLANATION OF EXAMPLE:-
• <stdio.h> :- Standard Input Output Header File.
• <conio.h> :- Console Input Output Header File.
• Void main/ Int main:- It is main function of program with this isn’t run
program it shows error again and again to you.
• Void main :- Mainly it is used for characters.
• Int main:- It is used to declaring all values.
• Printf:- It is used to printing values.
• Scanf:- It is used to given value by user.
• Return 0:- It is used to end the process.
FORMAT SPECIFIER:-
• %d :- INTEGER.
• %s :- STRING.
• %f :- FLOAT.
• %c :- CHARACTER.
• %lf :- LONG FLOAT(DOUBLE).
• %p :- POINTER.
• /n :- NEW LINE.
• /t :- NEW TAB.
• /u :- UNSIGNED VALUE.
TYPES OF OPERATORS:-
• Arithmetic Operators:- (+,-,*,\,%)
• Relational Operators:- (<,<=,>,>=,==,!=)
• Assignment Operators:- (+=,-=,\=,*=,%=,&=,^=,|=,<<,>>)
• Logical Operators:- (&&,||,!)
• Bitwise Operators:- (&,|,^,!,~)
• Conditional Operators:- (a+b*c\d)
• Increment decrement operators:- (a++, ++a, a--, --a)
CONDITIONAL STATEMENTS:-
• There are four types of conditional statement:-
• IF
• IFELSE
• ELSEIFLADDER
• NESTEDIF
CONDITIONAL STATEMENTS:-
• IF:- if statement tests the condition. It is executed if condition is true.
• Syntax:-
1.if(condition){
2.//code to be executed
3.}
CONDITIONAL STATEMENTS:-
• IFELSE:-if-else statement also tests the condition.
• It executes if block if condition is true otherwise else block is executed.
• Syntax:-
1.if(condition){
2.//code if condition is true
3.}else{
4.//code if condition is false
5.}
CONDITIONAL STATEMENTS:-
• ELSEIFLADDER:-if-else-if ladder statement executes one condition from multiple statements.
• Syntax:-
1.if(condition1){
2.//code to be executed if condition1 is true
3.}else if(condition2){
4.//code to be executed if condition2 is true
5.}
6.else if(condition3){
7.//code to be executed if condition3 is true
8.}
9....
10.else{
11.//code to be executed if all the conditions are false
12.}
CONDITIONAL STATEMENTS:-
• NESTED IF:-if blocks are present one after another with the same scope, then that condition is termed as a
Nested if condition.
• Syntax:-
• if ( base_condition)
•{
• // if base_condition is true control goes to base_condition2
• if(base_condition1)
• {
• if(base_condition2)
• ..........................
• ..........................
• }
•}
LOOPING STATEMENTS:-
• There are 3 types of looping statement:-
• FOR LOOP
• WHILE LOOP
• DO WHILE LOOP
LOOPING STATEMENTS:-
• FOR LOOP:-for loop is used to iterate a part of the program several
times.
• Syntax:-
1.for(initialization; condition; incr/decr){
2.//code to be executed
3.}
LOOPING STATEMENTS:-
• WHILE LOOP:-while loop is used to iterate a part of the program
several times.
• If the number of iteration is not fixed, it is recommended to use while
loop than for loop.
• Syntax:-
1.while(condition){
2.//code to be executed
3.}
LOOPING STATEMENTS:-
• DO WHILE LOOP:-do-while loop is executed at least once because
condition is checked after loop body.
• Syntax:-
1.do{
2.//code to be executed
3.}while(condition);
Switch Statement:-
• SWITCH:-switch statement executes one statement from multiple conditions.
• It is like if-else-if ladder statement in C++.
• Syntax:-
1.switch(expression){
2.case value1:
3. //code to be executed;
4. break;
5.case value2:
6. //code to be executed;
7. break;
8.......
9.
10.default:
11.//code to be executed if all cases are not matched;
12.break;
13.}
Break Statement:-
• BREAK:-break is used to break loop or switch statement.
• It breaks the current flow of the program at the given condition.
• In case of inner loop, it breaks only inner loop.
• Syntax:-
1.jump-statement;
2.break;
Continue Statement:-
• CONTINUE:-continue statement is used to continue loop.
• It continues the current flow of the program and skips the remaining
code at specified condition.
• In case of inner loop, it continues only inner loop.
• Syntax:-
1.jump-statement;
2.continue;
Goto Statement:-
• GOTO:- goto statement is also known as jump statement.
• It is used to transfer control to the other part of the program.
• It unconditionally jumps to the specified label.
• Syntax:-
• Jump-statement;
ARRAY:-
• The maximum number of elements that can be stored in an array
• Array can store multiple same datatypes values in it.
• Array can store their size with the help of square brackets[].
• It declares their values in curly brackets only{}.
• E.g:- int arr[5]={1,2,3,4,5};
• Types of array:-
• Single Dimensional Array.
• Two Dimensional Array.
• Multi Dimensional Array.
ARRAY:-
• SINGLE DIMENSIONAL ARRAY:- It is also known as 1D Array.
• Syntax:- datatype array_name array_size = value;
• Eg:- int arr[5]={1,2,3,4,5};
ARRAY:-
• TWO DIMENSIONAL ARRAY:- It is known as 2D Array.
• A two-dimensional array using rows and columns; there are I number
of rows and j number of columns.
• Syntax:-datatype array_name array_size = value;
• Eg:- int arr[4][3]={{1,2,3,4}{5,6,7}};
ARRAY:-
• MULTI DIMENSIONAL ARRAY:- It is known as 3D Array.
• Syntax:-datatype array_name array_size = value;
E.g:- int arr[3][3][3]= {{1,2,3,
4,5,6,
7,8,9}
{4,5,6,
3,2,1,
6,8,1}
{9,8,7,
6,5,4,
3,2,1}}
What is Function:-
• A function can be called multiple times to provide reusability and
modularity to the C program.
• By using functions, we can avoid rewriting same logic/code again and
again in a program.
• we can say that the collection of functions creates a program.
What is Function:-
• Function declaration A function must be declared globally to tell the compiler about the
function name, function parameters, and return type.
• Function call Function can be called from anywhere in the program.
• The parameter list must not differ in function calling and function declaration.
• We must pass the same number of functions as it is declared in the function declaration.
• Function definition It contains the actual statements which are to be executed.
• It is the most important aspect to which the control comes when the function is called.
• It only one value can be returned from the function.
Syntax of Function:-