Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structure of C Programs

Similar presentations


Presentation on theme: "Structure of C Programs"— Presentation transcript:

1 Structure of C Programs
Yung-Hsiang Lu Purdue University

2 If you understand the previous example (first
If you understand the previous example (first.c), you can skip this lecture.

3 /. first. c. Created on: Jun 3, 2016. Author: yunglu
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; }

4 Comments between /* and */
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } Comments between /* and */

5 /. first. c. Created on: Jun 3, 2016. Author: yunglu
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } include header files

6 /. first. c. Created on: Jun 3, 2016. Author: yunglu
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; }

7 "main" is the starting point of a C program
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } "main" is the starting point of a C program

8 "main" returns an integer, EXIT_SUCCESS or EXIT_FAILURE
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } "main" returns an integer, EXIT_SUCCESS or EXIT_FAILURE

9 "main" takes two arguments, an integer and an char * *
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } "main" takes two arguments, an integer and an char * *

10 Their names are always "argc" and "argv". Do not change the names.
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } Their names are always "argc" and "argv". Do not change the names.

11 argc: number of arguments c = count
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } argc: number of arguments c = count

12 argv: values of arguments v = value
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } argv: values of arguments v = value

13 A function's body starts with { and ends with }
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } A function's body starts with { and ends with }

14 print a message in a given format f = formatting
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } print a message in a given format f = formatting

15 /. first. c. Created on: Jun 3, 2016. Author: yunglu
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } \n means a new line

16 This simple program always succeeds.
/* * first.c * * Created on: Jun 3, 2016 * Author: yunglu */ #include <stdio.h> #include <stdlib.h> int main(int argc, char * * argv) { printf("Hello C\n"); return EXIT_SUCCESS; } This simple program always succeeds.


Download ppt "Structure of C Programs"

Similar presentations


Ads by Google