C Programming :: Basic Concepts

Home > C Programming > Basic Concepts > General Questions

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

21 / 87

 What is the output of the following 'C' program?

#include
void main()
{
printf("%c", "abcdefgh"[4]);
}

AError

Be

Cd

Dabcdefgh

Answer: Option B

Explanation:

printf("%c","abcdefgh"[4]);............simply means the character at 4th index should be displayed.

Hence, the output is e.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

22 / 87

 What is the output of the following 'C' program ?

#include
void main()
{
char ch = 'A';
printf ("%d%d",sizeof(ch),sizeof('A'));
}

A1 1

B2 2

C1 4

D2 1

Answer: Option C

Explanation:

Here, 'ch' is a character type variable. 

The size of char is 1 byte, hence sizeof(ch) is equal to 1.

Whereas, 'A' is a character constant, which is seen as an int. We know the size of int is 4 bytes hence, sizeof('A') is equal to 4.

Therefore, the output is 1 4.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

23 / 87

 What is the output of the following 'C' program?

#include
void main()
{
printf("\n%d%d%d",sizeof("3"),sizeof("3"),sizeof (3));
}

A1 1 1

B1 2 2

C2 2 4

D2 2 1

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

24 / 87

 What is the output of the following 'C' program?

#include
void main()
{
printf("\n%x", -1 >> 4);
}

Affff

B0

C0fff

Dfff0

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

25 / 87

 What is the output of the following 'C' program ?

#include
void main()
{
unsigned int num;
int c = 0;
scanf("%u", &num);
for(; num; num >>=1)
{
if(num & 1)
c++;
printf ("%d", c);
}
}

AIt counts the number of bits which are on in the number num

BIt sets all bits in the number num to 1

CIt sets bits in the number num to 0

DNone of these

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

26 / 87

 What is the output of the following 'C' program?

#include
void main()
{
printf("%d", printf("tim"));
}

Asyntax error

Btim3

Cgarbage value

Dprints tim and terminates

Answer: Option B

Explanation:

First, tim is printed. Then, we know that printf() function returns the number of characters as argument. Here, 'tim' contains 3 characters, so 3 will be printed alongwith.

Hence, the output is tim3.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

27 / 87

 What is the output of the following program ?

nt main()
{
char x, y, z;
printf("%d", scanf ("%c%c%c", &x, &y, &z));
return 0;
}

Note: "abc" as input

Asyntax error

Bsegmentation violation

Cfatal error

D3

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

28 / 87

 What is the output of the following program ?

#include
int main()
{
int a;
if (a=0)
printf("a is zero");
else
printf ("a is not zero");
return 0;
}

Aa is zero

Bnothing

Ca is not zero

Dgarbage

Answer: Option C

Explanation:

Here, inside if we are actually initializing a=0, and we know that "0 is not equal to 0" will result to False, hence if block won't get executed.

Therefore, else block will get executed and the output will be a is not zero

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

29 / 87

 #include
void main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}

AConvert to Upper Case

BConver to Lower Case

CNo Ouptput No error

DCompiler error

Answer: Option D

Explanation:

Declaration of convert and format of getc() are wrong.

Workspace

NA
SHSTTON
0
Solv. Corr.
0
Solv. In. Corr.
0
Attempted
0 M:0 S
Avg. Time

30 / 87

 What is the output of the following C Program?

#include
int swap(int *a,int *b)
{
*a=*a+*b;*b=*a-*b;*a=*a-*b;
}
void main()
{
int x=10,y=20;
swap(&x,&y);
printf("x= %d y = %d\n",x,y);
}

Ax= 20 y = 10

Bx= 10 y = 20

CCompilation Error

DNone of these

Answer: Option A

Explanation:

This is one way of swapping two values.

Workspace