The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+12 votes
3.5k views

What does the following C-statement declare?

int (*f) (int * );
  1. A function that takes an integer pointer as argument and returns an integer

  2. A function that takes an integer as argument and returns an integer pointer

  3. A pointer to a function that takes an integer pointer as argument and returns an integer

  4. A function that takes an integer pointer as argument and returns a function pointer

asked in Programming by Veteran (59.6k points)
edited by | 3.5k views

5 Answers

+31 votes
Best answer
  1. A function that takes an integer pointer as argument and returns an integer $\Rightarrow int \ f (int *)$

  2. A function that takes an integer as argument and returns an integer pointer $\Rightarrow int * f (int )$

  3. A pointer to a function that takes an integer pointer as argument and returns an integer $\Rightarrow$

    int (*f) (int * );

So, answer is C.

answered by Boss (43k points)
edited by
+1
what will be the declaration for D ?

and for a pointer to a function which takes an integer pointer as argument , and returns an integer pointer.?
+5

1.  declaration for D ("A function that takes an integer pointer as argument and returns a function pointer")
int* f(int *)

 2. for a pointer to a function which takes an integer pointer as argument , and returns an integer pointer.
      int* (*f) (int *)
 

+4

@saurabh rai

1.  declaration for D ("A function that takes an integer pointer as argument and returns a integer pointer")
int* f(int *)

1.  declaration for D ("A function that takes an integer pointer as argument and returns a function pointer")
int ( * f(int *) ) ()

here f returns a pointer pointing to a function which returns int data and takes no input as arguments.

0
#VS can u write a program on it ??

int ( * f(int *) ) ()
+3

Read this, http://cseweb.ucsd.edu/~ricko/CSE131/rt_lt.rule.html

I call this "Brahmaastra" technique for solving such question.

0
thanks ashish
0

 Ayush Upadhya thanks

0
Declaration of  D will be   ( * f(int *) ) () ... am i right ??
0
ashish bhai u r great
+1
quiet interesting "astra"
+6 votes
Answer is option C... This is the proptotype to declare a pointer to a function
answered by Active (2k points)
+2 votes
Option c.
answered by Active (3.3k points)
+2 votes

http://www.geeksforgeeks.org/complicated-declarations-in-c/

Good information to go through

Answer C

answered by Loyal (8.5k points)
+2 votes

By clockwise spiral rule, answer is C

A very good read to read function description http://c-faq.com/decl/spiral.anderson.html

answered by Active (2.1k points)
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

40,992 questions
47,620 answers
146,892 comments
62,346 users