0% found this document useful (0 votes)
8 views

15.StorageClass FAQ

The document discusses various C programming concepts like functions, variables scope, static variables, extern keyword, compiling multiple source files etc. It contains code snippets demonstrating the concepts and instructions to compile and check the output.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

15.StorageClass FAQ

The document discusses various C programming concepts like functions, variables scope, static variables, extern keyword, compiling multiple source files etc. It contains code snippets demonstrating the concepts and instructions to compile and check the output.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1. //this source file name is main.c 2. // this file name is sum.

#include<stdio.h> int sum(int a, int b)


int sum(int,int); {
int main() return a+b;
{ }
int x=10,y=20;
printf(“%d”,sum(x,y));
Note: compile this file sum.c using gcc (step by step.
} Gcc -E, -S, -c etc..)
Note: compile this program step-by-step (gcc -E, -S, -c,
etc..)

3. 4.
Compile the above two files using Study nm command , using $man nm
gcc main.c sum.c observe the output of $nm a.out

5. int x=10; 6. extern int x;


void inc(void) void inc(void)
{ {
++x; ++x;
} }
int main() int main()
{printf(“x=%d\n”,x); { printf(“x=%d\n”,x);
inc(); inc();
inc(); inc();
inc(); inc();
printf(“x=%d\n”,x);} printf(“x=%d\n”,x); }
int x=10;

7. int x; 8. static int x=10;


void inc(void) void inc(void)
{ {
++x; ++x;
} }
int main() int main()
{ {
printf(“x=%d\n”,x); printf(“x=%d\n”,x);
inc(); inc();
inc(); inc();
inc(); inc();
printf(“x=%d\n”,x); printf(“x=%d\n”,x);
} }
int x=10;
9. 10.
main.c main.c
------------------------- -------------------------
int x = 10; static int x = 10;
void inc(void); void inc(void);
int main() int main()
{ {
inc(); inc();
inc(); inc();
inc(); inc();

} }

inc.c inc.c
--------------------------------- ---------------------------------
void inc(void) void inc(void)
{ {
extern int x;// also try without extern. extern int x;
++x; ++x;
} }

Note: compile two files as Note: compile two files as


$gcc main.c inc.c $gcc main.c inc.c

11. 12.
int x=10; int main()
int main() {
{ int a=1;
int y=x; switch(a)
int z=y; { int b=5;
printf(“%d %d %d”,x,y,z); case 1: printf(“b=%d\n”,b);
}
} }
13. //main.c 14. //inc.c
int i;
static void inc(void) void inc(void)
{ {
i++; int i;
} ++i;
int main() }
{
inc(); Note: compile along with program in 13th. as
inc(); $ gcc main.c inc.c
printf(“%d”, i); Also observe the a.out content.
} $ nm a.out

You might also like