MCQ

100 Multiple Choice Questions In C Programming – Part 5

This collection of 100 Multiple Choice Questions and Answers (MCQs) In C Programming : Quizzes & Practice Tests with Answer focuses on “C Programming”.
 

1. How many times do we get through the following loop?
int c = 10;

while (( c <11 ) { 
	printf("Hello World\n"); 
}

A 0

B 1

C 9

D it is an infinite loop

D
while (( c <11 ) {...} We tell the computer “As long as the condition is true (10 < 11), repeat the instructions between braces”.

 

 

2. Which data type is most appropriate for storing the value 57000 in a 32-bit system?

A signed short

B unsigned short

C long

D int

B
65000 is available in Short type range (16 bits) which occupies the least memory. signed short has a range of -32768 to 32767 and therefore we should use the unsigned short type.

 

 
 

3. Which of the following is a user-defined data type?

A typedef int Boolean;

B typedef enum {Monday, Tuesday, Wednesday, Thursday, Friday} Days;

C struct {char address[25], int age};

D All the answers are true

D
“typedef” and “struct” are used to define user-defined data types.

 

 

4. How many times do we get through the following loop?
for ( counter = 2; counter < 9; counter += 2 )

A 4

B 5

C 7

D 8

4
From 2 to 9 with Step = 2. So we get through the loop 4 times. (2 -> 4 -> 6 -> 8).

 

 

5. What is the size of int type?

A 4 Bytes

B 8 Bytes

C Depends on system and compiler

D Cannot be determined

C
The type size depends on the system.

 

6. What is the output of the following C program?
#include <stdio.h>

int main()
{
   signed char c;
   c= 235;
   printf("%d\n", c);
   return 0;
}

A 235

B -235

C Depends on compiler

D None of the above

C
The value of a variable of type “signed char” will be a negative value. The output is as follows:

$gcc prog2.c
$ a.out
-128

 

 
 

7. What happens after a return?

A The function stops and returns the indicated result

B The function continues and returns the indicated result

C The function continues and returns no result

D None of the above

A
After a return. The function stops and returns the indicated result.

 

 

8. What is the output of the following C program?
#include <stdio.h>

int main()
{
    char c;
    int i = 0;
    FILE *file;

    // write to the text file
    file = fopen("test.txt", "w+");
    fprintf(file, "%c", 'x');
    fprintf(file, "%c", -1);
    fprintf(file, "%c", 'y');
    fclose(file);

    // read from the text file
    file = fopen("test.txt", "r");
    while ((c = fgetc(file)) != -1)
        printf("%c", c);
    return 0;
}

A Display x

B Infinite loop

C Depends on what fgetc returns

D Depends on compiler

A
The output is as follows:

$gcc prog3.c
$ a.out
x

 

 

9. What does “short int” mean in C programming?

A basic data type

B qualifier

C short is the qualifier and int is the basic data type

D All the answers are true

C

 

 
 

10. What is the output of the following C program?
#include <stdio.h>

int main()
{
    float a = 0.1;
    if (a == 0.1)
        printf("equal\n");
    else
        printf("not equal\n");
}

A equal

B not equal

C the output depends on the compiler

D None of the above

B
The default value 0.1 is a value of type double which has a different representation than the float, resulting in inequality even after conversion. The output is as follows:

$gcc prog1.c
$ a.out
not equal

 

 

11. What is the output of the following C program?
#include <stdio.h>

int main()
{
    float a = 0.1;
    if (a == 0.1f)
        printf("equal\n");
    else
        printf("not equal\n");
}

A equal

B not equal

C the output depends on the compiler

D None of the above

A
To check the equality of a float number you have to follow the value with the f letter. The output is as follows:

$gcc prog2.c
$ a.out
equal

 

 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *