C programing

Page 30

It can’t be initialized

It can be initialized

a.)

Pointers and Functions

When the Argument is passed using pointer address of the memory location is passed instead of value. Example: #include<stdio.h> void swap(int *a,int *b); int main() { int n1=5,n2-10; swap(&n1,&n2); printf(“n1=%d \n”,n1); printf(“n2=%d’,n2); return 0; } void swap(int *a, int *b) { int temp; temp=*n1; *n1=*n2; *n2=temp; } The address of n1 and n2 are passed to the memory location of pointer a and b, So the value of the memory location changed the value in memory location also changed, clearly if the *a and *b are changed it will reflected in n1 & n2 This is known as call by reference.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.