Home / C Programming / Control Instructions :: Discussion

Discussion :: Control Instructions

  1. What will be the output of the program?

    #include
     int main() 
     {   
        char ch;    
        if(ch = printf(""))          
            printf("It matters\n");      
       else     
            printf("It doesn't matters\n");   
       return 0; 
    } 
    

  2. A.

    It matters

    B.

    It doesn't matters

    C.

    matters

    D.

    No output

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    printf() returns the number of charecters printed on the console.

    Step 1: if(ch = printf("")) here printf() does not print anything, so it returns '0'(zero).
    Step 2: if(ch = 0) here variable ch has the value '0'(zero).
    Step 3: if(0) Hence the if condition is not satisfied. So it prints the else statements.
    Hence the output is "It doesn't matters".

    Note: Compiler shows a warning "possibly incorrect assinment".


Be The First To Comment