C Functions and Pointers Set 1

Ques: 1 Which of the following operation can be applied on pointers?
A. Addition of two pointers.
B. Multiplication of a pointer with integer.
C. Dividing a pointer with a number.
D. None of these.
Description
Answer: D
None of the above operations can be applied on pointers instead addition of 
pointer with a number is allowed

Ques: 2 Which of the following is true about pointers?
A. pointer incremented always points to an immediately next location of its type.
B. a higher type pointer can store the address of lower type variables.
C. Subtraction operation is not allowed in pointers.
D. None of the above
Description
Answer: A

Ques: 3 Which of the following is true about the following declaration in C?
void fun();
A. It can be called as -> fun();
B. It may be called as -> fun(72);
C. Both A and B are true.
D. None.
Description
Answer: C

Only allowed in C.


Ques: 4 Which of the following is true about the following declaration in C?
void fun(void);
A. it can be called as -> fun();
B. it can be called as ->fun(72)
C. both A and B are true.
D. None of these.
Description
Answer: A
Fun(void) means no argument can be paased to it.

Ques: 5 What will be the output of the following program?
#include<stdio.h>
int fun(int no, int pow)
{
	static res=1;
	while(pow--)
	 res = res*no;
	return res;
}
int main()
{
	printf("%d %d",fun(5,2),fun(5,2));
	return 0;
}
A. 25 25
B. 25 625 
C. 625 25
D. None of these
Description
Answer: C

 Here res is static variable which will remain till the end of the program
 therefore result of second function call will be 25*5*5 i.e. 625.
 And as we know inside printf() fuction call will be made right to left 
 therefor final output will be 625 25


Ques: 6 What will be the output of the following program?
#include<stdio.h>
f(int a, int b)
{
	float x = a+10.15;
	float y = b+x;
	return x+y;
}
int main()
{
	float ff=f(5,10);
	printf("%f",ff);
}

A. Error :return type missing
B. 40.300000
C. 40.000000
D. Undefined behaviour
Description
Answer: C
One basic concept you should know is that default return type of any function in c is integer 
so here we are returning a float value i.e 40.300000 which will be type casted into integer 
at the time of returning from function because default return type is integer i.e 40 
then again we are storing the same value into a float variable so after typecasting it
 will become 40.000000 that is the value in ff which will be printed on the output screen.

Ques: 7 What will be the output of the following program?
#include<stdio.h>
int main()
{
	static int x=3;
	while(x-->=0){
		printf("%d",3);
		main();
	}
}


A. 333
B. 3333
C. Infinite loop
D. main function cannot be called externally.
Description
Answer: B
Init

Here x is static variable which will not be declared at each function call that’s why it is not an infinite loop and main function can be called externally.


Ques: 8 which of the following is true about functions in C?
A. A function can take more than one type of arguments but
          can return only one type of value.
B. A function can take only single type of argument but can return
          more than one values.
C. Both A and B are true.
D. Both A and B are false
Description
Answer: A
A is true.

Ques: 9 What will be the output of the following program?
#include<stdio.h>
int main()
{
	int x=2,y=3;
	x = ~x---y;
	if(x < y)
	{
		void f();
		printf("Yes");
	}
	else{
		void f();
		printf("No");
	}
		f();
	printf("%d",x);
}
void f()
{
	printf("GeeksBix");
}

A. YesGeeksBix-6
B. NoGeeksBix-6
C. Compile time error
D. None.
Description
Answer: C
Yes..! answer will be C because f() is declared only inside if and else block 
but outside of it declaration of f() is missing.

Ques: 10 What will be the output of the following program?
#include<stdio.h>
int f(int x)
{
	x = x++ + ++x ++x;
	x>30?return(10):return(20);
}
int main()
{
	int x = f(10);
	printf("%d",x);
}


A. 10
B. 20
C. Compile time Error
D. None


Description
Answer: C
Yes..! answer will be C because we cannot use return statements like this, 
instead it should be return(x>30?10:20);


comments powered by Disqus