C Programming Multiple Choice Question - Structure And Loops

This section focuses on the "Structure And Loops" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. In the following loop construct, which one is executed only once always.    for(exp1; exp2; exp3)

A. exp1
B. exp3
C. exp1 and exp3
D. exp1, exp2 and exp3

View Answer


2. The continue statment cannot be used with

A. for
B. while
C. do while
D. switch

View Answer


3. Which keyword can be used for coming out of recursion?

A. return
B. break
C. exit
D. both A and B

View Answer


4. goto can be used to jump from main to within a function?

A. TRUE
B. FALSE
C. May Be
D. Can't Say

View Answer


5. Which of the following is an invalid if-else statement?

A. if (if (a == 1)){}
B. if (a){}
C. if ((char) a){}
D. if (func1 (a)){}

View Answer


6. Switch statement accepts.

A. int
B. char
C. long
D. All of the above

View Answer


7. Which loop is guaranteed to execute at least one time.

A. for
B. while
C. do while
D. None of the above

View Answer


8. A labeled statement consist of an identifier followed by

A. ;
B. :
C. ,
D. =

View Answer


9. do-while loop terminates when conditional expression returns?

A. One
B. Zero
C. Non - zero
D. None of the above

View Answer


10. c = (n) ? a : b; can be rewritten asexp1 ? exp2 : exp3;

A. if(n){c = a;}else{c = b;}
B. if(!n){c = a;}else{c = b;}
C. if(n){c = b;}else{c = a;}
D. None of the above

View Answer


11. For loop in a C program, if the condition is missing?

A. it is assumed to be present and taken to be false
B. it is assumed to be present and taken to the true
C. it result in a syntax error
D. execution will be terminated abruptly

View Answer


12. Which of the following statement about for loop is true ?

A. Index value is retained outside the loop
B. Index value can be changed from within the loop
C. Goto can be used to jump, out of the loop
D. All of these

View Answer


13. Using goto inside for loop is equivalent to using

A. Continue
B. Break
C. Return
D. None of the above

View Answer


14. If switch feature is used, then

A. Default case must be present
B. Default case, if used, should be the last case
C. Default case, if used, can be placed anywhere
D. None of the above

View Answer


15. Which of the following comments about for loop are correct ?

A. Using break is equivalent to using a goto that jumps to the statement immediately following the loop
B. Continue is used to by-pass the remainder of the current pass of the loop
C. If comma operator is used, then the value returned is the value of the right operand
D. All of the above

View Answer


16. In the context of "break" and "continue" statements in C, pick the best statement.

A. "break" and "continue" can be used in "for", "while", "do-while" loop body and "switch" body.
B. "break" and "continue" can be used in "for", "while" and "do-while" loop body. But only "break" can be used in "switch" body.
C. "break" and "continue" can be used in "for", "while" and "do-while" loop body. Besides, "continue" and "break" can be used in "switch" and "if-else" body.
D. "break" can be used in "for", "while" and "do-while" loop body.

View Answer


17. In _______, the bodies of the two loops are merged together to form a single loop provided that they do not make any references to each other.

A. Loop unrolling
B. Strength reduction
C. Loop concatenation
D. Loop jamming

View Answer


18. What is the output of this program?

        
void main()
{
    if(!printf(""))
        printf("hello");
    else
        printf("world");
}

A. hello
B. world
C. Compilation Error
D. None of the above

View Answer


19. What is the output of this program?

#include <stdio.h>
void main()
{
    int a=10;
    if(a=5)
        printf("YES");
    else
        printf("NO");
}

A. YES
B. NO
C. Error
D. None of the above

View Answer


20. What is correct about the given program?

#include <stdio.h>
int x;
void main()
{
    if (x);
    else
        printf("Else");
}

A. if block will be executed
B. else block will be executed
C. Depends on value of x since it is undeclared
D. Compilation Error

View Answer


21. What is the output of this program?

#include <stdio.h>
int main()
{
    int a = 5;
    if (a == 6); a = 0;
    if (a == 5)
    a++;
    else a += 2;
    printf("%d", a);
    return 0;
}

A. 6
B. 8
C. 5
D. 2

View Answer


22. What is the output of this program?

    #include <stdio.h>
    int main()
    {
        int a = 1, b = 0;
        int c = (a++, b++) ? b : a;
        printf("%d", c);
        return 0; 
    }

A. 2
B. 1
C. 0
D. 3

View Answer


23. What is the output of this program?

int main()
{
 
    int a = 1, b = 0;
    int c = a%2 ? a++ : a-- ? a=0 : ++b ? b = 2 : b++ ;
    printf("%d", c);
    return 0;
}

A. 1
B. 2
C. 3
D. 0

View Answer


24. What will be the output of the program in 16 bit platform ?

#include <stdio.h>
int main()
{
 
    int a=2, b=1, c=2;
    switch(a)
    {
        case b:
        printf("You are in b ");
        break;
        case c:
        printf("You are in c ");
        break;
        default:printf("You are in default");
    }
    return 0;
}

A. You are in b
B. You are in c
C. You are in default
D. Compilation Error

View Answer


25. What will be output when you will execute following c code?

#include <stdio.h>
int main()
{
 
    int a=2;
    switch(a,a+1)
    {
        case 2:
            printf("You are in b ");
            break;
        case 3:
            printf("You are in c ");
            break;
        default:
            printf("You are in default");
    }
    return 0;
}

A. You are in b
B. You are in c
C. You are in default
D. Compilation Error

View Answer


26. What is the output of this program?

#include <stdio.h>
void main() {
    float a = 0.7;
    if ( a < 0.7 )
        printf( "Yes" );
    else
        printf( "No" );
}

A. Yes
B. No
C. Compilation Error
D. None of these

View Answer


27. What is the output of this program?

#include <stdio.h>
void main()
{   char a=0;
    for(a=0;a<=127;a++)
    {
        printf("%d ",a);
    }
}

A. 0 1 2 ... 127
B. 0 1 2 ... infinite times
C. Compilation Error
D. None of the above

View Answer


28. How many times the loop will execute ?

for(int i = 0 ; i < 10 ; i++)
{
    i  =  i*2;
    i--;
}

A. 10
B. 5
C. 0
D. Infinite

View Answer


29. What is the output of this program?

#include <stdio.h>
void main()
{
  int j = -5;
  for(;j;printf("%d ", j++));
}

A. -5 to -1
B. -5 to 0
C. -5 to infinity
D. Compilation Error

View Answer


30. What is the output of this program?

  
void main()
{
    int x=0;
    for(;;)
    {
        if(x==3)
            break;
        printf("%d ",++x);
    }

}

A. 1 2 3
B. 0 1 2 3
C. 1 2
D. Compilation Error

View Answer


31. How many times letsfindcourse will be printed?

#include <stdio.h>
int main()
{
    int i = -5;
    while (i <= 5)
    {
        if (i >= 0)
            break;
        else
        {
            i += 1;
            continue;
        }
        printf("letsfindcourse");
    }
    return 0;
}

A. 5 times
B. 10 times
C. 0 times
D. Infinite times

View Answer


32. What is the output of this program?

#include <stdio.h>
void main()
{
    int a = 3;
    while (a--)
    {
        int a = 10;
        a--;
        printf("%d ", a);
    }
}

A. 9 9 9
B. 9 8 7
C. 2 1 0
D. Infinite loop

View Answer


33. Which of the given statment is true about the given code ?

int main()
{
 int i = 0;
 for ( ; i < 5 ; )
 { 
   if (i < 5)
     printf("Hello", i++);
   else
     continue;
   printf("World");
 }
 return 0;
}

A. It will print hello 5 times followed by World one time
B. It will print helloWorld 5 times
C. It will print helloWorld infinite times
D. Compilation Error

View Answer


34. How many times value of j is checked in the below code ?

#include 
    int main()
    {
        int j = 0;
        do {
            j++;
            printf("");
        } while (j < 5);
    }

A. 3
B. 4
C. 5
D. 1

View Answer


35. What is the output of the following code?

int main()
{
    int i = 0;
    switch(i)
    {
    case 0 : i++;
    case 1 : i+++2;
    case 2 : ++i;
    }
    pritnf("%d",i++);

    return 0;
}

A. 2
B. 3
C. 4
D. 5

View Answer


36. How many x are printed?

    for(i=0,j=10;i < j;i++,j--) 
        printf("x");

A. 10
B. 5
C. 4
D. 6

View Answer


37. How many x are printed?

    for(i=-2,j=5;i < j;i++,j--) 
        printf("x");

A. 10
B. 5
C. 4
D. 6

View Answer


38. What will be the output of the program?

 int a=0,b=2;
 if(a=0) b=0;
 else b*=10;

A. 0
B. 20
C. 2
D. None of the above

View Answer


39. What will be the output of the program?

 int a=2,b=2;
 if(a!=0) 
    b=0;
 else 
    b*=10;
 printf("%d",b);

A. 0
B. 20
C. 2
D. None of the above

View Answer


40. What will be the output of the program?

 int a=2,b=2;
 if(a && 0) 
     b=0;
 else 
     b*=10;
  printf("%d",b);

A. 0
B. 20
C. 2
D. None of the above

View Answer







Also check :


Discussion



* You must be logged in to add comment.