396 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

3 votes
3 votes
1 answer
1
Storm_907 asked Apr 16, 2023
441 views
Please explain this question void main() { int a =300; char *ptr = (char*) &a ; ptr++; *ptr=2; printf("%d" , a); }
4 votes
4 votes
4 answers
3
Manoj Kumar Pandey asked May 22, 2019
797 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 fol...