C Loops & Control – I

 

C Loops & Control - I



Ques. 1: What will be the output result of below code?

#include 
 
int main()
{
    int i = 2048;
    for (; i; i >>= 1)
        printf("Embedded system training");
    return 0;
}
How many times Embedded system training will appear
A. 11
B. 12
C. code will not compile.
D. infinite loop.



Ques. 2: What will be the output result of below code?

#include 
int main()
{
    int i = 10;
    switch (i)
    {
        case '10': printf("Professional");
                break;
        case '11': printf("Training");
                break;
        default: printf("Institute");
    }
    return 0;
}

A. Professional  
B. Training
C. Institute
D. Compile time error.



Ques. 3: consider following code, what is the output?

#include
int add(){
printf("don't add here ");
return 0;
}

int main()
{
       int i=1024;
       if (add(i))
       {
       i=9;
       }else
       {
       i=12;
       }
       printf("%d",i);

       return 0;
}

A. don't add here 9
B. don't add here 12
C. error while compile
D. 12



Ques. 4: find the output

#include
main()
{
    int check=0;
    if (check);
    else
    {
         printf("Hello PTI");
    }
    printf(" see you soon.\n");
}

A. Hello PTI see you soon.
B. else without a previous if
C. see you soon
D. none of above



Ques. 5: find the output

#include
main()
{
    int check=0;
    if (check);
    {

    }
    else
    {
         printf("Hello PTI");
    }
    printf(" see you soon.\n");
}

A. Hello PTI see you soon.
B. else without a previous if
C. see you soon
D. none of above



Ques 6: What is the output?
 
#include  
#define DISP(i, limit) do \ 
                        { \ 
                            if (i++ < limit) \ 
                            { \ 
                                printf("PTinstitute\n"); \ 
                                continue; \ 
                            } \ 
                        }while(0) 
  
int main() 
{ 
    int i = 0; 
    DISP(i, 3); 
    return 0; 
} 

A. 0
B. PTinstitute
C. 3
D. Compile time error


Ques 7. what is the output?

#include 
int main()
{
    int i = 4;
    switch (i)
    {
        case 1+0: printf("PTI");
                break;
        case 2+2: printf("Good");
                break;
        default: printf("Test");
    }
    return 0;
}

A.  PTI
B.  Good
C.  Test
D.  none of the above



Ques 8: find the outpout?

#include 
#define TRUE 1
#define FALSE 0

int main()
{
    int i = 3;

    switch (i & 1)
    {
        case FALSE: printf("FALSE");
                break;
        case TRUE: printf("TRUE");
                break;
        default: printf("Default");
    }
    return 0;
}

A. TRUE
B. FALSE
C. Default
D. None of the above



Ques 9: find the outpout?

#include 

enum num{FALSE, TRUE };

int main()
{
    int i = 3;

    switch (i & 1)
    {
        case FALSE: printf("FALSE");
                break;
        case TRUE: printf("TRUE");
                break;
        default: printf("Default");
    }
    return 0;
}

A. Default
B. FALSE
C. TRUE
D. None of the above




Ques 10: find the outpout?

#include 
int main()
{
    int m;
    if (printf("0"))
        m = 3;
    else
        m = 5;
    printf("%d", m);

    return 0;
}

Options:

A. 05
B. 03
C. 5
D. Compile time error


Ques 11: find the outpout?

#include
int main()
{
   int k;
   for (k = 5; k!=0; k--)
     printf("n = %d", k--);
   return 0;
}

Options:
A. n = 5 n= 3 n=1 
B. n= 5, n= 4, n= 3 n=2 n=1
C. Infinite loop
D. 5 4 3 2 1


Ques 12: find the outpout?

#include 
int main()
{
    int g = 4, num = 8;
    do {
        num /= g;
    } while(g--);

    printf ("%d \n", num);
    return 0;
}

options:
A. 1
B. 0
C. Runtime error
D. Compile time error

Ques 13: find the outpout?

#include 
int main()
{
    int g = 4, num = 8, true=1;
    do {
        num = num / g;
        true --;
    } while(true);

    printf ("%d \n", num);
    return 0;
}

options:
A. 1
B. 0
C. 2
D. Compile time error


Ques 14: find the outpout?

#include 
int main()
{
    int h = 4, y= 8;
    if(y/h==2)
        printf("\n h=2");
    else
        printf("\n h!=2");

    return 0;
}
options:
A. h=2
B. h!=2
C. Compiletime error
D. none of the above


Ques 15: find the outpout?

#include 
int main()
{
    int m = 1;
    if(m)
        {
            m--;
            printf("\n %d ", m);
            if(!m)
                printf("%d ",m );
            else
                printf("%d ",m);
        }
    else
        printf("\n h!=2");

    return 0;
}

options:
A. 1 1
B. 0 0
C. Compiletime error
D. 1 0

Answers

1. B 2. C 3. B 4. A 5. D 6. B 7. B 8. A 9. C 10. B 11. C 12. C 13. C 14. A 15. B