Advertisements

Search results for function pointer

Example:[1]

            What is a function pointer in C?
          
Option A:

            A pointer variable which points to another function.
            
Option B:

            A pointer variable which points to another string variable.
            
Option C:

            A pointer variable which points to another int variable.
            
Option D:

            None of the given above.
            
Correct Answer: option A
Example:[2]

            A state machine in c can be implemented by ___________?
          
Option A:

            Using an if else statements.
            
Option B:

            Using a switch case statements.
            
Option C:

            Using function pointers.
            
Option D:

            All mentioned above.
            
Correct Answer: option D
Example:[3]

            What is the error in the following program?
#include <stdio.h>
int add(int, int);
typedef int (*f)(int,int);
void main()
{
	f = add;
}
int add(int a, int b)
{
	return a+b;
}
          
Option A:

            Error in declaring the function pointer.
            
Option B:

            Error in initializing the function pointer.
            
Option C:

            Error in defining prototype for the function add. 
            
Option D:

            Error in the function definition of add.
            
Correct Answer: option B
Example:[4]

            What is the error in the following program?
#include <stdio.h>
int add(int, int);
typedef int (*f)(int,int);
void main()
{
	int ret = 0;
	f fptr = NULL;
	fptr = add;
	ret = (*fptr)(3,2);
	printf("Result is:%d\n", ret);
}
int add(int a, int b)
{
	return a+b;
}
          
Option A:

            Error in declaring the function pointer f.
            
Option B:

            Error in initializing the function pointer f.
            
Option C:

            Error in calling the function pointer f. 
            
Option D:

            There is no error in the program.
            
Correct Answer: option D
Example:[5]

            What is the error in the following program?
#include <stdio.h>
typedef int (*f)(int,int);
int addop(f ptr, int a, int b)
{
	int ret = 0;
	ret = (ptr)(a,b);
	return ret;
}
int add(int a, int b)
{
	return a+b;
}
void main()
{
	int ret = 0;
	f fptr = NULL;
	fptr = add;
	ret = addop(fptr,3,2);
	printf("Result is:%d\n", ret);
}
          
Option A:

            Error in declaring the function pointer f.
            
Option B:

            Error in initializing the function pointer f.
            
Option C:

            Error in calling the function addop.
            
Option D:

            Error in the function definition of addop.
            
Correct Answer: option D

 Search Links


 Popular C search MCQs


 Popular C search examples