Find the output of C programs
Program 1
gd.c
#include <stdio.h> int main() { int _ = 5, __ = 10, ___; ___ = _ + __; printf("%i\n", ___); return 0; }
Show OutputOutput
godarda@gd:~$ gcc gd.c
godarda@gd:~$ ./a.out 15 godarda@gd:~$
Program 2
gd.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
godarda@gd:~$ gcc gd.c
godarda@gd:~$ ./a.out 20 godarda@gd:~$
Program 3
gd.c
#include <stdio.h> void main() { int x; x = 10, 20, 30; printf("%d\n", x); }
Show OutputOutput
godarda@gd:~$ gcc gd.c
godarda@gd:~$ ./a.out 10 godarda@gd:~$
Comments and Reactions
What Next?
C Control Statements