Advertisements

Search results for typedef

Example:[1]

            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:[2]

            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:[3]

            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