You are on page 1of 50

C LANGUAGE:-

• C language developed by Dennis.M.Ritchie and Brain Kerninghan.


• C language is founded in the “Bell Laboratory”(Bell Labs).
• C language developed in the year 1972.
• “The C Language” First edition published in the year 1978.
• Then name of “The C Language” is “ANSI C” .
• Book was purchased by ANSI C in the year 1988.
• ANSI C(American National Standard Institute).
• ANSI C become ISO registered in the year 1999.
• ISO(International Standard Organisation).
• After all this it becomes ISO registered book and its named given ANSI/ISO C.
FEATURES:-
• It is a simple compiling language.
• It is a used to write numerous of codes.
• It is a simple and understable language.
• It has inbuilt and user defined data types.
• C lang only defined functions.
• C lang is a pop language [POP:-(Procedure Oriented Language)].
VARIABLES AND VALUES:-
• A=5
• A is a Variable.
• 5 is a Value.
DEFINED TERMS:-

• 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:-

1 Function declaration return_type function_name


(argument list);

2 Function call function_name (argument_list)

3 Function definition return_type function_name


(argument list) {function body;}
Function Method:-
• There are two methods to pass the data into the function in C
language, i.e., call by value and call by reference.
Call By value:-
• In call by value method, the value of the actual parameters is copied
into the formal parameters.
• The value of the variable is used in the function call in the call by
value method.
• In call by value method, we can not modify the value of the actual
parameter by the formal parameter.
• In call by value, different memory is allocated for actual and formal
parameters since the value of the actual parameter is copied into the
formal parameter.
Call by reference
• In call by reference, the address of the variable is passed into the
function call as the actual parameter.
• The value of the actual parameters can be modified by changing the
formal parameters since the address of the actual parameters is passed.
• In call by reference, the memory allocation is similar for both formal
parameters and actual parameters.
Recursion:-
• Recursion is the process which Syntax:-
1.if (test_for_base)
comes into existence when a 2.{
function calls a copy of itself to 3. return some_value;
work on a smaller problem. 4.}
5.else if (test_for_another_base)
• Any function which calls itself 6.{
is called recursive function, and 7. return some_another_value;
8.}
such function calls are called 9.else
recursive calls. 10.{
11. // Statements;
• Recursion involves several 12. recursive call;
numbers of recursive calls. 13.}
String:-
• String is a group of characters.
• The termination character ('\0') is important in a string since it is the
only way to identify where the string ends.
• When we define a string as char s[10], the character s[10] is implicitly
initialized with the null in the memory.
String Function:-
No. Function Description
1) strlen(string_name) returns the length of string name.

2) strcpy(destination, source) copies the contents of source string to


destination string.

3) strcat(first_string, second_string) concates or joins first string with second


string. The result of the string is stored in first
string.
4) strcmp(first_string, second_string) compares the first string with second string. If
both strings are same, it returns 0.

5) strrev(string) returns reverse string.


6) strlwr(string) returns string characters in lowercase.

7) strupr(string) returns string characters in uppercase.


String Function:-
• STRING LENGTH:- The strlen() function returns the length of the
given string. It doesn't count null character '\0’.
• STRING COPY:- The strcpy(destination, source) function copies the
source string in destination.
• STRING CONCATE:- The strcat(first_string, second_string)
function concatenates two strings and result is returned to first_string.
• STRING COMPARE:- The strcmp(first_string, second_string)
function compares two string and returns 0 if both strings are equal.
String Function:-
• STRING REVERSE:- The strrev(string) function returns reverse of
the given string.
• STRING LOWER:- The strlwr(string) function returns string
characters in lowercase.
• STRING UPPER:- The strupr(string) function returns string
characters in uppercase.
String Function:-
• STRING STRING:- The strstr() function returns pointer to the first
occurrence of the matched string in the given string.
• It is used to return substring from first match till the last character.
• SYNTAX:- char *strstr(const char *string, const char *match)
• String: It represents the full string from where substring will be
searched.
• Match: It represents the substring to be searched in the full string.
Structure:-
• Structure in c is a user-defined data type that enables us to store the collection of different data
types.
• Each element of a structure is called a member.
• Structures simulate the use of classes and templates as it can store various information
• The ”struct” keyword is used to define the structure.
• SYNTAX:-
1.struct structure_name
2.{
3. data_type member1;
4. data_type member2;
5. .
6. .
7. data_type memeberN;
8.};
Union:-
• Union can be defined as a user-defined data type which is a collection of different variables
of different data types in the same memory location.
• The union can also be defined as many members, but only one member can contain a value at
a particular point in time.
• Union is a user-defined data type, but unlike structures, they share the same memory location.
• SYNTAX:-
1.union abc
2.{
3. int a;
4.char b;
5.}
Pointer:-
• The pointer in C language is a variable which stores the address of another
variable.
• This variable can be of type int, char, array, function, or any other pointer.
• The size of the pointer depends on the architecture.
• The pointer in c language can be declared using * (asterisk symbol).
• It is also known as indirection pointer used to dereference a pointer.
• Declaration:-
1.int n = 10;
2.int* p = &n; // Variable p of type pointer is pointing to the address of the varia
ble n of type integer.
File Function:-
No. Function Description
1 fopen() opens new or existing file
2 fprintf() write data into the file
3 fscanf() reads data from the file
4 fputc() writes a character into the file

5 fgetc() reads a character from file

6 fclose() closes the file


7 fseek() sets the file pointer to given position

8 fputw() writes an integer to file


9 fgetw() reads an integer from file
10 ftell() returns current position
11 rewind() sets the file pointer to the beginning of
the file
File Function:-
• We must open a file before it can be read, write, or update.
• The fopen() function is used to open a file.
• Syntax:- FILE *fopen( const char * filename, const char * mode );
• The fclose() function is used to close a file.
• The file must be closed after performing all the operations on it.
• Syntax:- int fclose( FILE *fp );
File Function:-
Mode Description
r opens a text file in read mode
w opens a text file in write mode
a opens a text file in append mode
r+ opens a text file in read and write mode
w+ opens a text file in read and write mode
a+ opens a text file in read and write mode
rb opens a binary file in read mode
wb opens a binary file in write mode
ab opens a binary file in append mode
rb+ opens a binary file in read and write mode
wb+ opens a binary file in read and write mode
ab+ opens a binary file in read and write mode
File Function:-
• The fputc() function is used to write a single character into file.
• The fgetc() function returns a single character from the file.
• The fputs() function writes a line of characters into file.
• The fgets() function reads a line of characters from file.
Fprintf and Fscanf:-
• The fprintf() function is used to write set of characters into file. It
sends formatted output to a stream.
• Syntax:-
int fprintf(FILE *stream, const char *format [, argument, ...])
• The fscanf() function is used to read set of characters from file. It
reads a word from the file and returns EOF at the end of file.
• Syntax:-
int fscanf(FILE *stream, const char *format [, argument, ...])
Dynamic Memory Allocation:-
• The concept of dynamic memory allocation in c language enables
the C programmer to allocate memory at runtime.
• Dynamic memory allocation in c language is possible by 4 functions
of stdlib.h header file.
1.malloc()
2.calloc()
3.realloc()
4.free()
Dynamic Memory Allocation:-
malloc() allocates single block of • Syntax of malloc:-ptr=(cast-
requested memory.
type*)malloc(byte-size)
calloc() allocates multiple block of • Syntax of calloc:-ptr=(cast-
requested memory. type*)calloc(number, byte-size)
• Syntax of realloc:-
realloc() reallocates the memory
occupied by malloc() or ptr=realloc(ptr, new-size)
calloc() functions.
• Syntax of free:- free(ptr)
free() frees the dynamically
allocated memory.

You might also like