Quantcast
Channel: User Alex Lop. - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Alex Lop. for What will be the output of the given code below?

$
0
0

You can split this code into something longer but probably more readable like this:

#include<stdio.h>int main(){    int a=0, b=1, c=2;    int *ptr;    if (a + 1 == 1) { // this will be true        ptr = &b;    }    else {        ptr = &a;    }    if (a != 0) { // this will be false        *ptr = b;    }    else {        *ptr = c;    }    printf(“%d, %d, %d \n” a , b, c );    return 0;}

Based on the initial values, a + 1 == 1 will be true, so ptr = &b;.

Since a=0; then a != 0 will be false and thus *ptr = c;

==> same as b = c;

So the expected output is

0, 2, 2


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>