C Programming MCQ with Answers Set-1

This post contains a computer network related to 20 multiple-choice questions (C Programming SET-1) that help you to go through the subject and prepare you for c programming related questions in a competitive exam.

C Programming MCQ Test Series Set-1

  • Total Number of Questions: 20

  • Each question carries equal marks i.e. 1

  • No Negative Marking

Page 1 of 2

1. Consider the following C program.

#include<stdio.h>

struct Ournode{

char x,y,z;

};

int main(){

struct Ournode p = {'1', '0', 'a'+2};

struct Ournode *q = &p;

printf ("%c, %c", *((char*)q+1), *((char*)q+2));

return 0;

}

The output of this program is:
A.
B.
C.
D.
2. Consider the following ANSI C program :

Int main() {

Integer x;

Return 0;

Which one of the following phases in a seven-phase C compiler will throw an error?
A.
B.
C.
D.
3. Consider the following ANSI C program.
#include <stdio.h>
Int main(){
Int arr[4][5];
Int i, j;
For (i=0; i<4; i++){
For (j=0; j<5; j++){
arr[i][j]=10*i+j;
}
}
printf(“%d”, *(arr[1]+9));
return 0;
}
A.
B.
C.
D.
4.

Consider the following ANSI C code segment:
Z=x+3+y->f1+y->f2;
For (i=0; i<200: i=i+2){
If (z>i){
p=p+x+3;
q=q+y->f1;
} else {
p=p+y->f2;
q=q+x+3;
}
}
Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and dereference operations (of the form y->f1 or y->f2) in the optimized code, respectively, are:

A.
B.
C.
D.
5.

Consider the following C function.

void convert (int n) {

if(n<0)

printf ( %d”, n);

else {

convert(n/2);

printf(n%d",n%2);

Which one of the following will happen when the function convert is called with any positive integer n as argument?

A.
B.
C.
D.
6.

Consider the following C program:

#include <stdio.h>

int r () {

static int num=7;

}

return num--;

}

int main() {

for (r();r();r())

printf("%d", r.());

return 0;

}

Which one of the following values will be displayed on the execution of the programs?

A.
B.
C.
D.
7.

Consider the following C program:

#include<stdio.h>

void fun1(char *s1, char *s2){

char *tmp;

tmp = s1;

s1 = s2;

s2 = tmp;

}

void fun2(char **s1, char **s2){

char *tmp;

tmp = *s1;

*s1 = *s2;

*s2 = tmp;

}

int main(){

char *str1 = "Hi", *str2 = "Bye";

fun1(str1, str2); printf("%s %s ", str1, str2);

fun2(&str1, &str2); printf("%s %s", str1, str2);

return 0;

}

The output of the program above is

A.
B.
C.
D.
8. Consider the following C code. Assume that unsigned long int type length is 64 bits.

unsigned long int fun (unsigned long int n) {

unsigned long int i, j = 0, sum = 0;

for (i = n; i > 1; i = i/2) j++;

for ( ; j > 1; j = j/2) sum++;

return(sum);

}

The value returned when we call fun with the input 240 is
A.
B.
C.
D.
9. Consider the following ANSI C program.

#include(stdio.h)

int main ()

{

int i, j, count;

Count=0;

i=0;

for (j=-3; j<=3; j++)

{

If ((j>=0) && (i++))

count=count+i;

printf(“%d”), count);

return 0;

}

Which one of the following options is correct?
A.
B.
C.
D.
10. The following C program is executed on a Unix/Linux system:

#include <unistd.h>

int main()

{int i;

for (i=0; i<10; i++)

if (i%2 == 0) fork();

return 0;

}

The total number of child processes created is____________.

 
A.
B.
C.
D.

 

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments