SlideShare a Scribd company logo
2
Most read
Programming in C –Call By
Prof. A. Syed Mustafa, HKBK College of Engineering
Program to find area of a circle using #define.
#include<stdio.h>
#define PI 3.1412
int main()
{
int radius; float area;
printf("Enter the radius: ");
scanf("%d", &radius);
area=PI*radius*radius;
printf("Area=%.2f",area);
return 0;
}
Use of #if, #elif, #else and #endif :
The preprocessor directives #if, #elif, #else and #endif allows to
conditionally compile a block of code based on predefined symbols.
#include<stdio.h>
#define MAX 100
void main( )
{
#if (MAX)
printf("MAX is defined");
#else
printf ("MAX is not defined");
#endif
}
Preprocessor Directive / Macros
The C preprocessor [CPP] is a macro processor that is used
automatically by the C compiler to transform programmer defined
programs before actual compilation takes place. It is called a macro
processor because it allows the user to define macros, which are short
abbreviations for longer constructs.
It instructs the compiler to do required pre-processing before the
actual compilation. All preprocessor directives begin with the #
symbol (known as pound or hash).
List of pre-processor directives:
1. #include: This is used insert a particular header from another file.
2. #define, #undef : These are used to define and un-define
conditional compilation symbols.
3. #if, #elif, #else, #endif : These are used to conditionally skip
sections of source code.
Example:
#include “demo.h”
 tells CPP to get demo.h from the local directory and add the
content to the current source file.
#define PI 3.1412 /* defines symbolic constant */
 This directive tells the CPP to replace symbolic constant pi
with 3.1412.
#define SIZE 5 /* SIZE will be replaced with 5 */
Programming in C –Call By
Prof. A. Syed Mustafa, HKBK College of Engineering
MEMORY ALLOCATION FUNCTIONS
1. Static Memory Allocation:
Memory space allocated from stack at compile time for variables
declared in the program is fixed, it cannot be altered during
execution-time. This is called static memory allocation.
Example: int a[5]; float d;
2. Dynamic Memory Allocation
It is the process of allocating memory-space during execution-time
i.e. run time from Heap. If there is an unpredictable storage
requirement, then the dynamic allocation technique is used.
This allocation technique uses predefined functions to allocate and
release memory for data during execution-time.
There are 4 library functions for dynamic memory allocation:
malloc( ), calloc( ), free( ), realloc( )
These library functions are defined under "stdlib.h"
1. malloc( ) -memory allocation
This function is used to allocate the required memory-space
during execution-time.
The syntax is shown below:
data_type *p;
p=(data_type*)malloc(size);
Here p is pointer variable.
data_type can be int, float or char. size is number of bytes to be
allocated.If memory is successfully allocated, then address of the first
byte of allocated space is returned. If memory allocation fails, then
NULL is returned.
For ex: int *ptr;
ptr=(int*)malloc(100*sizeof(int));
The above code will allocate 200 bytes assuming sizeof(int)=2 bytes.
2. calloc( ) - contiguous allocation
This function is used to allocate the required memory-size during
execution-time and at the same time, automatically initialize
memory with 0's.
syntax :
data_type *p;
p=(data_type*)calloc(n,size);
Ex:
p=(int*)calloc(25,sizeof(int));
3. free( )
Dynamically allocated memory with either calloc( ) or malloc( ) can
be deallocated using free( ) explicitly to release space.
syntax:
free(ptr);
4. realloc() -reallocation
If the previously allocated memory is insufficient or more than
sufficient. Then, we can change memory-size previously allocated
using realloc().
The syntax is shown below:
ptr=(data_type*)realloc(ptr,newsize);
void main( )
{ int i;
int *a= (int *)malloc(10);
for(i=0;i<5;i++)
*(a+i)=i+10;
for(i=0;i<5;i++)
printf(“%dt”,*(a+i)10;
}
Output: 10 11 12 13 14
Programming in C –Call By
Prof. A. Syed Mustafa, HKBK College of Engineering
Pointers
A Pointer is just an address of the data stored in memory.
A pointer is a variable whose value is the address of
another variable, i.e., direct address of the memory
location.
Syntax: <variable_type> *<name>=&variable; eg:- int *a=&b;
‘*’ used to declare a pointer variable and also used to retrieve the value
from the pointed memory location. ‘*’ is also called as derefence operator.
#include <stdio.h>
void main ()
{
int a = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &a; /* store address of var in pointer variable*/
printf("Address of variable a is: %xn", &a );
/* address stored in pointer variable */
printf("Address stored in variable ip is: %xn", ip );
/* access the value using the pointer */
printf("Value of *ip variable: %dn", *ip );
}
Output:
Address of variable a is: bffd8b3c
Address stored in variable ip is: bffd8b3c
Value of *ip variable: 20
Actual Parameter
 The parameter’s value (or arguments) we provide while calling
a function is known as actual arguments.
 Parameter Written In Function Call is Called “Actual Parameter”
 Actual parameters are parameters as they appear in function calls.
 The actual value that is passed into the function by a caller.
Formal Parameter
 Formal parameters are parameters as they appear in function
declarations.
 the identifier used in a method to stand for the value that is passed
into the function by a caller.
 Parameter Written In Function Definition is Called “Formal Parameter”
 While declaring a function, the arguments list of parameters we
specify are known as formal parameters.
Example
Programming in C –Call By
Prof. A. Syed Mustafa, HKBK College of Engineering
CALL BY ADDRESS
The call to the function passes variable’s
address to the called function. The actual
arguments are not copied to the formal
arguments, the addresses of actual
arguments (or parameters) are passed to
the formal parameters. Hence any
operation performed by function on
formal arguments / parameters affects
actual parameters.
void swap(int *x, int *y)
{ int t=*x; *x=*y; *y=t;
}
void main( ) {
int a=5, b=10 ;
printf("Before swap: a=%d,b=%d",a,b);
swap(&a,&b); /*calling swap function*/
printf("After swap: a= %d,b=%d",a,b);
}
Output:
Before swap: a=5,b=10
After swap: a=10,b=5
Because variable declared ‘a’, ‘b’ in
main() is different from variable ‘x’, ’y’ in
swap(). Only variable names are
different but both a and x, b and y point
to the same memory address locations
respectively.
CALL BY REFERENCE
The call to the function passes base address to
the called function. The actual arguments are
not copied to the formal arguments, only
referencing is made. Hence any operation
performed by function on formal arguments /
parameters affects actual parameters.
void change(int b[ ])
{
b[0]=10; b[1]=20; b[2]=30;
}
void main( )
{
int a[3]={ 5, 15, 25 } ;
printf("BeforeChange:%d,%d,%d",a[0],a[1],a[2]);
change(a); /*calling swap function*/
printf("AfterChange:%d,%d,%d",a[0],a[1],a[2]);
}
Output:
BeforeChange: 5,15,25
AfterChange: 10,20,30
Because array variable declared ‘b’ in change() is
referencing/ pointing to array variable ‘a’ in
main(). Only variable name is different but
both are pointing / referencing to same
memory address locations.
CALL BY VALUE
The call to the function passes either the values
or the normal variables to the called function.
The actual arguments are copied to the formal
arguments, hence any operation performed by
function on arguments doesn’t affect actual
parameters.
void swap(int a, int b)
{
int t=a; a=b; b=t;
}
void main( )
{
int a=5, b=10 ;
printf("Before swap: a=%d,b=%d",a,b);
swap(a,b); /*calling swap function*/
printf("After swap: a= %d,b=%d",a,b);
}
Output:
Before swap: a=5,b=10
After swap: a=5,b=10
Because variable declared ‘a’, ‘b’ in main() is
different from variable ‘a’, ’b’ in swap(). Only
variable names are similar but their memory
address are different and stored in different
memory locations.
Programming in C –Call By
Prof. A. Syed Mustafa, HKBK College of Engineering
STACKS
• A stack is a special type of data structure where elements are inserted from one end and elements are deleted from the same
end.
• Using this approach, the Last element Inserted is the First element to be deleted Out, and hence, stack is also called LIFO data
structure.
• The various operations performed on stack:
Insert: An element is inserted from top end. Insertion operation is called push operation. Delete: An element is
deleted from top end. Deletion operation is called pop operation. Overflow: Check whether the stack is full or not.
Underflow: Check whether the stack is empty or not.
• This can be pictorially represented as shown below:
APPLICATIONS OF STACK
1) Conversion of expressions: The compiler converts the infix expressions into postfix expressions using stack.
2) Evaluation of expression: An arithmetic expression represented in the form of either postfix or prefix can be easily evaluated
using stack.
3) Recursion: A function which calls itself is called recursive function.
4) Other applications: To find whether the string is a palindrome, to check whether a given expression is valid or not.
Programming in C –Call By
Prof. A. Syed Mustafa, HKBK College of Engineering
PRIMITIVE AND NON-PRIMITIVE DATA TYPES
Data type specifies the type of data stored in a
variable. The data type can be classified into two
types: 1) Primitive data type and 2)Non-Primitive data
type
Primitive Data Type
• The primitive data types are the basic data types
that are available in most of the programming
languages.
• The primitive data types are used to represent single
values.
Integer: This is used to represent a number without
decimal point. Eg: int a=12;
Float: This is used to represent a number with
decimal point. Eg: float a=45.1; double b=67.3;
Character: This is used to represent single character
Eg: char ch=‘C’; char ch1= ‘a’;
Non Primitive Data Type
• The data types that are derived from primary data types
are known as non-Primitive data types.
• These datatypes are used to store group of values.
• The non-primitive data types are
Arrays, Structure
Stacks, Linked list
Queue, Binary tree

More Related Content

PPTX
Recursive Function
PPTX
Function C programming
PPTX
Input buffering
PPTX
Constructor in java
PPTX
User defined functions in C
PPTX
Dynamic memory allocation
PPT
RECURSION IN C
PPTX
Unit 3. Input and Output
Recursive Function
Function C programming
Input buffering
Constructor in java
User defined functions in C
Dynamic memory allocation
RECURSION IN C
Unit 3. Input and Output

What's hot (20)

PPTX
Unit 9. Structure and Unions
PPTX
C Programming: Control Structure
PPTX
Function Pointer
PPTX
Conditional Statement in C Language
PPT
Shell programming
PPTX
Functions in c++
PPTX
Lexical analysis - Compiler Design
PPTX
Function overloading and overriding
PPTX
Functions in c language
PPTX
Input-Buffering
PDF
Function overloading ppt
PPTX
File in C language
PDF
Operator Precedence Grammar
PPTX
Exception handling c++
PPTX
Specification-of-tokens
PDF
Issues in the design of Code Generator
PPTX
Loop optimization
PDF
Data Structures & Algorithm design using C
PPTX
Strings in C language
Unit 9. Structure and Unions
C Programming: Control Structure
Function Pointer
Conditional Statement in C Language
Shell programming
Functions in c++
Lexical analysis - Compiler Design
Function overloading and overriding
Functions in c language
Input-Buffering
Function overloading ppt
File in C language
Operator Precedence Grammar
Exception handling c++
Specification-of-tokens
Issues in the design of Code Generator
Loop optimization
Data Structures & Algorithm design using C
Strings in C language
Ad

Viewers also liked (20)

PPTX
Parameter passing to_functions_in_c
PPTX
Call by value
PPT
e computer notes - Writing basic sql select statements
PDF
e computer notes - Reference variables
PPT
e computer notes - Manipulating data
PPT
All important c programby makhan kumbhkar
PPTX
C programming language
DOC
Palindrome number program in c
PPT
Functions
PDF
Module 03 File Handling in C
DOC
C lab-programs
PPT
Structure c
PPT
File in c
PPT
File handling in c
PPTX
UNIT 10. Files and file handling in C
DOCX
C programs
DOCX
C Programming
PPTX
File handling in c
PPTX
C++ programming function
Parameter passing to_functions_in_c
Call by value
e computer notes - Writing basic sql select statements
e computer notes - Reference variables
e computer notes - Manipulating data
All important c programby makhan kumbhkar
C programming language
Palindrome number program in c
Functions
Module 03 File Handling in C
C lab-programs
Structure c
File in c
File handling in c
UNIT 10. Files and file handling in C
C programs
C Programming
File handling in c
C++ programming function
Ad

Similar to Pointers and call by value, reference, address in C (20)

PPTX
Advance topics of C language
PPTX
Technical Interview
PPTX
unit_2.pptx
PPTX
Programming in C sesion 2
PPTX
pointers.pptx
PPTX
C concepts and programming examples for beginners
PPTX
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
PDF
The best every notes on c language is here check it out
PPT
Advanced pointers
PPT
presentation_functions_1443207686_140676.ppt
PPTX
UNIT 6structureofcprogrammingforppt.pptx
PPTX
unit_2 (1).pptx
PDF
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 3.pdf
PPT
C programming
PPTX
Programming_in_C_language_Unit5.pptx course ATOT
PPTX
Functions in C
PDF
C interview-questions-techpreparation
PDF
C interview questions
PPTX
Function (rule in programming)
PDF
VIT351 Software Development VI Unit1
Advance topics of C language
Technical Interview
unit_2.pptx
Programming in C sesion 2
pointers.pptx
C concepts and programming examples for beginners
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
The best every notes on c language is here check it out
Advanced pointers
presentation_functions_1443207686_140676.ppt
UNIT 6structureofcprogrammingforppt.pptx
unit_2 (1).pptx
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 3.pdf
C programming
Programming_in_C_language_Unit5.pptx course ATOT
Functions in C
C interview-questions-techpreparation
C interview questions
Function (rule in programming)
VIT351 Software Development VI Unit1

More from Syed Mustafa (20)

PDF
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
PDF
18CSL58 DBMS LAB Manual.pdf
PDF
Syed IoT - module 5
PDF
IoT - module 4
PDF
15CS81- IoT- VTU- module 3
PDF
15CS81- IoT Module-2
PDF
Internet of Things - module 1
PDF
15CS664- Python Application Programming- Question bank 1
PDF
15CS664- Python Application Programming VTU syllabus
PDF
15CS664- Python Application Programming - Module 3
PDF
15CS664-Python Application Programming - Module 3 and 4
PDF
15CS664 Python Question Bank-3
PDF
Data structures lab manual
PDF
Usp notes unit6-8
PDF
Grid computing notes
PDF
Unix system programming
PDF
answer-model-qp-15-pcd13pcd
PDF
VTU PCD Model Question Paper - Programming in C
PDF
Data structures lab c programs
PDF
Infix prefix postfix expression -conversion
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf
Syed IoT - module 5
IoT - module 4
15CS81- IoT- VTU- module 3
15CS81- IoT Module-2
Internet of Things - module 1
15CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming VTU syllabus
15CS664- Python Application Programming - Module 3
15CS664-Python Application Programming - Module 3 and 4
15CS664 Python Question Bank-3
Data structures lab manual
Usp notes unit6-8
Grid computing notes
Unix system programming
answer-model-qp-15-pcd13pcd
VTU PCD Model Question Paper - Programming in C
Data structures lab c programs
Infix prefix postfix expression -conversion

Recently uploaded (20)

PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
737-MAX_SRG.pdf student reference guides
PDF
III.4.1.2_The_Space_Environment.p pdffdf
DOCX
573137875-Attendance-Management-System-original
PPTX
UNIT 4 Total Quality Management .pptx
PDF
PPT on Performance Review to get promotions
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Geodesy 1.pptx...............................................
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Well-logging-methods_new................
PPT
Mechanical Engineering MATERIALS Selection
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Construction Project Organization Group 2.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
737-MAX_SRG.pdf student reference guides
III.4.1.2_The_Space_Environment.p pdffdf
573137875-Attendance-Management-System-original
UNIT 4 Total Quality Management .pptx
PPT on Performance Review to get promotions
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Model Code of Practice - Construction Work - 21102022 .pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
additive manufacturing of ss316l using mig welding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Geodesy 1.pptx...............................................
Internet of Things (IOT) - A guide to understanding
Well-logging-methods_new................
Mechanical Engineering MATERIALS Selection
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Construction Project Organization Group 2.pptx

Pointers and call by value, reference, address in C

  • 1. Programming in C –Call By Prof. A. Syed Mustafa, HKBK College of Engineering Program to find area of a circle using #define. #include<stdio.h> #define PI 3.1412 int main() { int radius; float area; printf("Enter the radius: "); scanf("%d", &radius); area=PI*radius*radius; printf("Area=%.2f",area); return 0; } Use of #if, #elif, #else and #endif : The preprocessor directives #if, #elif, #else and #endif allows to conditionally compile a block of code based on predefined symbols. #include<stdio.h> #define MAX 100 void main( ) { #if (MAX) printf("MAX is defined"); #else printf ("MAX is not defined"); #endif } Preprocessor Directive / Macros The C preprocessor [CPP] is a macro processor that is used automatically by the C compiler to transform programmer defined programs before actual compilation takes place. It is called a macro processor because it allows the user to define macros, which are short abbreviations for longer constructs. It instructs the compiler to do required pre-processing before the actual compilation. All preprocessor directives begin with the # symbol (known as pound or hash). List of pre-processor directives: 1. #include: This is used insert a particular header from another file. 2. #define, #undef : These are used to define and un-define conditional compilation symbols. 3. #if, #elif, #else, #endif : These are used to conditionally skip sections of source code. Example: #include “demo.h”  tells CPP to get demo.h from the local directory and add the content to the current source file. #define PI 3.1412 /* defines symbolic constant */  This directive tells the CPP to replace symbolic constant pi with 3.1412. #define SIZE 5 /* SIZE will be replaced with 5 */
  • 2. Programming in C –Call By Prof. A. Syed Mustafa, HKBK College of Engineering MEMORY ALLOCATION FUNCTIONS 1. Static Memory Allocation: Memory space allocated from stack at compile time for variables declared in the program is fixed, it cannot be altered during execution-time. This is called static memory allocation. Example: int a[5]; float d; 2. Dynamic Memory Allocation It is the process of allocating memory-space during execution-time i.e. run time from Heap. If there is an unpredictable storage requirement, then the dynamic allocation technique is used. This allocation technique uses predefined functions to allocate and release memory for data during execution-time. There are 4 library functions for dynamic memory allocation: malloc( ), calloc( ), free( ), realloc( ) These library functions are defined under "stdlib.h" 1. malloc( ) -memory allocation This function is used to allocate the required memory-space during execution-time. The syntax is shown below: data_type *p; p=(data_type*)malloc(size); Here p is pointer variable. data_type can be int, float or char. size is number of bytes to be allocated.If memory is successfully allocated, then address of the first byte of allocated space is returned. If memory allocation fails, then NULL is returned. For ex: int *ptr; ptr=(int*)malloc(100*sizeof(int)); The above code will allocate 200 bytes assuming sizeof(int)=2 bytes. 2. calloc( ) - contiguous allocation This function is used to allocate the required memory-size during execution-time and at the same time, automatically initialize memory with 0's. syntax : data_type *p; p=(data_type*)calloc(n,size); Ex: p=(int*)calloc(25,sizeof(int)); 3. free( ) Dynamically allocated memory with either calloc( ) or malloc( ) can be deallocated using free( ) explicitly to release space. syntax: free(ptr); 4. realloc() -reallocation If the previously allocated memory is insufficient or more than sufficient. Then, we can change memory-size previously allocated using realloc(). The syntax is shown below: ptr=(data_type*)realloc(ptr,newsize); void main( ) { int i; int *a= (int *)malloc(10); for(i=0;i<5;i++) *(a+i)=i+10; for(i=0;i<5;i++) printf(“%dt”,*(a+i)10; } Output: 10 11 12 13 14
  • 3. Programming in C –Call By Prof. A. Syed Mustafa, HKBK College of Engineering Pointers A Pointer is just an address of the data stored in memory. A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Syntax: <variable_type> *<name>=&variable; eg:- int *a=&b; ‘*’ used to declare a pointer variable and also used to retrieve the value from the pointed memory location. ‘*’ is also called as derefence operator. #include <stdio.h> void main () { int a = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ ip = &a; /* store address of var in pointer variable*/ printf("Address of variable a is: %xn", &a ); /* address stored in pointer variable */ printf("Address stored in variable ip is: %xn", ip ); /* access the value using the pointer */ printf("Value of *ip variable: %dn", *ip ); } Output: Address of variable a is: bffd8b3c Address stored in variable ip is: bffd8b3c Value of *ip variable: 20 Actual Parameter  The parameter’s value (or arguments) we provide while calling a function is known as actual arguments.  Parameter Written In Function Call is Called “Actual Parameter”  Actual parameters are parameters as they appear in function calls.  The actual value that is passed into the function by a caller. Formal Parameter  Formal parameters are parameters as they appear in function declarations.  the identifier used in a method to stand for the value that is passed into the function by a caller.  Parameter Written In Function Definition is Called “Formal Parameter”  While declaring a function, the arguments list of parameters we specify are known as formal parameters. Example
  • 4. Programming in C –Call By Prof. A. Syed Mustafa, HKBK College of Engineering CALL BY ADDRESS The call to the function passes variable’s address to the called function. The actual arguments are not copied to the formal arguments, the addresses of actual arguments (or parameters) are passed to the formal parameters. Hence any operation performed by function on formal arguments / parameters affects actual parameters. void swap(int *x, int *y) { int t=*x; *x=*y; *y=t; } void main( ) { int a=5, b=10 ; printf("Before swap: a=%d,b=%d",a,b); swap(&a,&b); /*calling swap function*/ printf("After swap: a= %d,b=%d",a,b); } Output: Before swap: a=5,b=10 After swap: a=10,b=5 Because variable declared ‘a’, ‘b’ in main() is different from variable ‘x’, ’y’ in swap(). Only variable names are different but both a and x, b and y point to the same memory address locations respectively. CALL BY REFERENCE The call to the function passes base address to the called function. The actual arguments are not copied to the formal arguments, only referencing is made. Hence any operation performed by function on formal arguments / parameters affects actual parameters. void change(int b[ ]) { b[0]=10; b[1]=20; b[2]=30; } void main( ) { int a[3]={ 5, 15, 25 } ; printf("BeforeChange:%d,%d,%d",a[0],a[1],a[2]); change(a); /*calling swap function*/ printf("AfterChange:%d,%d,%d",a[0],a[1],a[2]); } Output: BeforeChange: 5,15,25 AfterChange: 10,20,30 Because array variable declared ‘b’ in change() is referencing/ pointing to array variable ‘a’ in main(). Only variable name is different but both are pointing / referencing to same memory address locations. CALL BY VALUE The call to the function passes either the values or the normal variables to the called function. The actual arguments are copied to the formal arguments, hence any operation performed by function on arguments doesn’t affect actual parameters. void swap(int a, int b) { int t=a; a=b; b=t; } void main( ) { int a=5, b=10 ; printf("Before swap: a=%d,b=%d",a,b); swap(a,b); /*calling swap function*/ printf("After swap: a= %d,b=%d",a,b); } Output: Before swap: a=5,b=10 After swap: a=5,b=10 Because variable declared ‘a’, ‘b’ in main() is different from variable ‘a’, ’b’ in swap(). Only variable names are similar but their memory address are different and stored in different memory locations.
  • 5. Programming in C –Call By Prof. A. Syed Mustafa, HKBK College of Engineering STACKS • A stack is a special type of data structure where elements are inserted from one end and elements are deleted from the same end. • Using this approach, the Last element Inserted is the First element to be deleted Out, and hence, stack is also called LIFO data structure. • The various operations performed on stack: Insert: An element is inserted from top end. Insertion operation is called push operation. Delete: An element is deleted from top end. Deletion operation is called pop operation. Overflow: Check whether the stack is full or not. Underflow: Check whether the stack is empty or not. • This can be pictorially represented as shown below: APPLICATIONS OF STACK 1) Conversion of expressions: The compiler converts the infix expressions into postfix expressions using stack. 2) Evaluation of expression: An arithmetic expression represented in the form of either postfix or prefix can be easily evaluated using stack. 3) Recursion: A function which calls itself is called recursive function. 4) Other applications: To find whether the string is a palindrome, to check whether a given expression is valid or not.
  • 6. Programming in C –Call By Prof. A. Syed Mustafa, HKBK College of Engineering PRIMITIVE AND NON-PRIMITIVE DATA TYPES Data type specifies the type of data stored in a variable. The data type can be classified into two types: 1) Primitive data type and 2)Non-Primitive data type Primitive Data Type • The primitive data types are the basic data types that are available in most of the programming languages. • The primitive data types are used to represent single values. Integer: This is used to represent a number without decimal point. Eg: int a=12; Float: This is used to represent a number with decimal point. Eg: float a=45.1; double b=67.3; Character: This is used to represent single character Eg: char ch=‘C’; char ch1= ‘a’; Non Primitive Data Type • The data types that are derived from primary data types are known as non-Primitive data types. • These datatypes are used to store group of values. • The non-primitive data types are Arrays, Structure Stacks, Linked list Queue, Binary tree