03 Intro To C
03 Intro To C
03 Intro To C
Programming Languages
Section 3: Intro to C
Section 3 Topics
3-2
Basic structure
3-3
Hello world
printf(“Hello World\n”);
return 0;
}
3-4
Compilation
• When using an IDE like Eclipse, you often use a
“build” button (the “hammer” button in Eclipse)
• This is fine, but you should know what is
actually happening.
• C programs are compiled into object code by a
compiler.
– gcc ( GNU Compiler Collection) is probably the most
common open source version
– clang is also widely available (common on Mac)
– Other systems (Windows, Unix, BSD, etc) have their
own variations
– All should understand the same source files,
assuming they conform to a recent C language
standard.
3-5
gcc
3-6
Compiler…cont’d
• The following trivial command will produce an
executable with the default name a.out
gcc hello.c
cpp hello.c
3-8
cpp directives
3-9
cpp directive substitution
3-10
Header files
printf(“Hello World\n”);
return 0;
}
3-12
What is stdio.h?
3-13
More header files
3-15
Header purpose…cont’d
3-16
The C standard libraries
3-17
Printing to the screen
3-18
printf()
3-19
printf output specifiers
3-20
Printing error messages
3-21
Summary