GATE | GATE-CS-2005 | Question 1

What does the following C-statement declare? [1 mark]

filter_none

edit
close

play_arrow

link
brightness_4
code

int ( * f) (int * ) ;

chevron_right


(A) A function that takes an integer pointer as argument and returns an integer.
(B) A function that takes an integer as argument and returns an integer pointer.
(C) A pointer to a function that takes an integer pointer as argument and returns an integer.
(D) A function that takes an integer pointer as argument and returns a function pointer


Answer: (C)

Explanation: The steps to read complicated declarations :

1)Convert C declaration to postfix format and read from left to right.

2)To convert expression to postfix, start from innermost parenthesis, If innermost parenthesis is not present then start from declarations name and go right first. When first ending parenthesis encounters then go left. Once the whole parenthesis is parsed then come out from parenthesis.



3)Continue until complete declaration has been parsed.

At First, we convert the following given declaration into postfix:

int ( * f) (int * )

Since there is no innermost bracket, so first we take declaration name f, so print “f” and then go to the right, since there is nothing to parse, so go to the left. There is * at the left side, so print “*”.Come out of parenthesis. Hence postfix notation of given declaration can be written as follows:

f * (int * ) int

Meaning: f is a pointer to function (which takes one argument of int pointer type) returning int .

Refer https://www.geeksforgeeks.org/complicated-declarations-in-c/

This solution is contributed by Nirmal Bharadwaj.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.