451 views
0 votes
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?

2 Answers

1 votes
1 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'
edited by
0 votes
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

 

Related questions

110
views
2 answers
1 votes
kirmada asked Jun 20
110 views
#include <stdio.h> int main() { // Write C code here int i=10,*p,**q,***r; p=&i; *p=15; q=&p; **q=20; r=&q; ***r=*p+1; printf("%d",i); return 0; }answer the output as integer _________
519
views
1 answers
3 votes
Storm_907 asked Apr 16, 2023
519 views
Please explain this question void main() { int a =300; char *ptr = (char*) &a ; ptr++; *ptr=2; printf("%d" , a); }
622
views
2 answers
0 votes
prerona_99 asked Oct 31, 2021
622 views
main () {static char *s[] = { ice , green , cone , please ,};static char **ptr[] = {s+3,s+2,s+1,s};char ***p = ptr;printf( \n%s , **++p);printf( ... \n%s , p[-1][-1]+1);} cone, ase, reenice, green, conegreen, cone, pleaseNone of the above
881
views
4 answers
4 votes
Manoj Kumar Pandey asked May 22, 2019
881 views
https://gateoverflow.in/?qa=blob&qa_blobid=14433986388826671915int main() { int a = 10; int *b = &a; scanf("%d",b); printf("%d",a+50); }What will be the Output of the following code if input given is $25$ ?