Home » Aptitude Questions and Answers » C Aptitude Questions and Answers

C Declaration and Initialization Aptitude Questions and Answers



This section contains aptitude questions and answers on C language Declarations and Initialization.

1) What will be the output of following program ?
int main(){
    int m=10;
	int x=printf("%d ",m);
	printf("%d",x);
	return 0;
}
  1. 10 3
  2. 103
  3. 10 2
  4. 102

2) What will be the output of following program ?
int main(){
	int x='A';
	printf("%02X",x);
	return 0;
}
  1. 65
  2. 97
  3. Error
  4. 41

3) What will be the output of following program ?
int main(){
	char a=0b1010;
	printf("%02X",a);
	return 0;
}
  1. 0A
  2. A
  3. 0a
  4. 10

4) What will be the output of following program (on 32 bit compiler)?
int main(){
	char a=2*2+2;
	printf("%d",a);
	return 0;
}
  1. 0
  2. Garbage
  3. 6
  4. 8

5) What will be the output of following program ?
int main(){
	unsigned char x=-1;
	printf("%02X",x);
	return 0;
}
  1. 0xFFFFFFFF
  2. FF
  3. 0xFF
  4. ff

6) Which is the correct name of a variable?

(A) -var (B) var-1 (C) _var (D) var_1

  1. Only (A)
  2. Only (B)
  3. Both (A) and (B)
  4. Both (C) and (D)

7) Which special character can be used to separate two parts (words) of a variable/identifier name?

  1. - (Hyphen)
  2. _ (Underscore)
  3. $ (Dollar)
  4. # (Hash)

8) What will be the result of following program?

#include <stdio.h>
int main()
{
	char x='AB';	
	printf("%c",x);	
	return 0;
}
  1. Error
  2. Run successfully
  3. Run with warnings
  4. None of these

9) Will following string be terminated with NULL?

char str[]={'H','e','l','l','o'};
  1. YES
  2. NO

10) Predict the output of following program.

#include <stdio.h>

int main()
{
	int (x)=10;
	printf("x= %d",x);
	
	return 0;
}
  1. x= 10
  2. x= 0
  3. Error
  4. None of these

11) Predict the output of following program.

#include <stdio.h>

int main()
{
	int i=50;
	const int x=i++;
	
	printf("x= %d",++x);
	
	return 0;
}
  1. x= 50
  2. x= 51
  3. x= 52
  4. Error

12) Predict the output of following program.

#include <stdio.h>

int main()
{
	int a=(10,20);
	
	printf("a= %d",a);
	
	return 0;
}
  1. a= 10
  2. a= 20
  3. a= 30
  4. Error






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.