Guess The Output series 5

Explanation of guess the output questions posted on our Instagram Page.

1) Guess the output

Instagram

The output of above C Program is D) 3 -2.
Why?
Initially the values of m and n are 5 and 3 respectively.
For your information:
a += b is same as a = a+b
a -= b is same as a = a-b
a *= b is same as a = a*b
a /= b is same as a = a/b
a %= b is same as a = a%b
and so on…

The above expression
m += n -= m acts like m = m + (n = n-m);
First of all, bracket will execute so the value of n becomes
n = n - m i.e. n = 3 - 5. n = -2
The updated expression looks like
m = m + (-2)
Final value of m is m = 5 - 2 which is equal to 3.

So the output of above C Program is 3 -2.

Click on Execute button to Run above code:


2) Question On Array

Question
Question

We know that 1[arr] is same as arr[1]. Initially arr[2] is filled with garbage values.
Then 5 is assigned to arr[0] and 10 is assigned to arr[1].
printf(“%d”, -1[arr]) is nothing but printf(“%d”, – arr[1]). The value at arr[1] is 10.
So the output of above C Program is -10.

Click on Execute button to Run above code:


3) Type Casting

The output of above C Program is B) 49.
ASCII equivalent of the character will be displayed in conversion of char to int in C/C++ Programming Language.
The ASCII value of 0 is 48, 1 is 49 and so on.
You can print ASCII values and equivalent character using C or C++ Language.

//Program to Print ASCII Value and its equivalent character
#include<stdio.h>

int main() {
    int i;
    for(i=48; i<100; i++)
    {
        printf("%d : %c \n", i, i);
    }
    
    return 0;
    
}

Click on Execute button to Run above code:


4) Switch Case

Output of above C Program is C) 20.
We can place default block anywhere inside switch. It will execute if no cases matched.
The statements which are written above cases (i.e. m = m+10;) never executes. The control is transfer to the matching case so the statements written above case not executed.


5) printf in C

The syntax of printf is
int printf (const char* c-string, …);
Where c-string is the string passed to printf function. If there is format specifiers(i.e. %d, %c, %p …) in the c-string then additional arguments can be passed with c-string.

f in printf(print formatted) stands for formatted not function.

First of all, printf(3+”hello”) is same as printf(“hello”+3).
The length of “hello” is 5. 3+”hello” means skip first 3 characters(i.e. hel) and print the remaining characters(i.e. lo)

Above code can be written like this

#include<stdio.h> 
int main() 
{ 
    int hello = 1;
    char *str = "hello"; 
    printf(str+3); 
    
    return 0;
} 

The output of above C Program is D) lo

If you need more information about this question, check the pinned comments of this post https://www.instagram.com/p/CP0ibuygV8b/

Click on Execute button to Run above code:


For more programming related questions and fun,
Follow us on Instagram.
 https://www.instagram.com/computer_science_engineering_/


Admin

Leave a Reply

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

Back to top