Find the output of C programs
Program 1
codeaft.c
#include <stdio.h> int main() { int _ = 5, __ = 10, ___; ___ = _ + __; printf("%i\n", ___); return 0; }
Show OutputOutput
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out 15 codeaft@codeaft:~$
Program 2
codeaft.c
#include <stdio.h> int main() { int a = 20; { int a = 40; // variables can have same name in different scope } printf("%d\n", a); return 0; }
Show OutputOutput
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out 20 codeaft@codeaft:~$
Program 3
codeaft.c
#include <stdio.h> void main() { int x; x = 10, 20, 30; printf("%d\n", x); }
Show OutputOutput
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out 10 codeaft@codeaft:~$
Comments and Reactions
What Next?
C Control Statements