0 0 votes Can we pass pointers in the arguments of a function? If yes then do we pass the value the pointer holds or the address of the pointer? Programming in C + – ranarajesh495 874 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes Yes we can pass pointers as an argument of a function Pointers itself contains address of any data item value. For example int a = 10; int *b =&a; here 'b' contains address of 'a' and at address of 'a' contains the value = 10. if we simply pass ' &b ' it contains address and if we pass ' *b ' then it contains value at the address stored in 'b' Priyanka17 answered Oct 11, 2018 • edited Oct 11, 2018 by Priyanka17 Priyanka17 comment Share Follow See all 2 Comments 2 2 Comments reply ranarajesh495 commented Oct 11, 2018 reply Follow flag @priyanka17 Thanx, it was very helpful, can you please also illustrtae through an example 0 0 replyShare Priyanka17 commented Oct 11, 2018 reply Follow flag example: you can check call by value and call by reference program for better understanding add(int a, int b) { int c = a+b ; return c; } add1(int *a1 , int *b1) { *a1++;// a1 gets updated *b1++;//b1 gets updated int c=*a1 + *b1 ; return c; } void main() { int a, b, a1, b1, c1, c2; a=1; b=2; a1=3; b1=4; c1= add(a,b); printf(a,b,c1);// output a=1 b=2 c=3 c2= add( &a, &b ); printf(a1,b1,c2);// output a1=4 b1=5 c2=9 } 0 0 replyShare Please log in or register to add a comment.
0 0 votes We of course can - otherwise printf function can never work because the first argument to it is a "pointer to char". And when we pass a pointer, its value is being passed - but the value being a pointer is expected to be an address of some other object. char *s = "hello"; printf(s); char a[2] = {'a', '\0'}; printf(a); char b = '\0'; printf(&b); int d = 9; printf("%d", d); // here address of the string literal "%d" is passed to printf Arjun answered Oct 11, 2018 Arjun comment Share Follow 0 reply Please log in or register to add a comment.