1_introduction to c programming
TRANSCRIPT
-
8/2/2019 1_Introduction to C Programming
1/15
Introduction to C programming
The C programing language was designed byDennis Ritchie at Bell laborataries in early1970s.
It was developed in conjunction with thedevelopment of UNIX .
-
8/2/2019 1_Introduction to C Programming
2/15
C : charecteristics
C takes middle way between a low levelassembly language
Direct access to memory layout throughpointer manipulation
Concise syntax , small set of keywords
And a high level programming language like
java Block structures
Some encpsulation of code (throughfunctions)
-
8/2/2019 1_Introduction to C Programming
3/15
Elements of a C program
C development environment includes
A set of standard libraries and their headerfiles
Application source and its header files
Compiler to convert the source to object for apaticular platfrom
Linker to resolve external references andproduce executable module
-
8/2/2019 1_Introduction to C Programming
4/15
User program structure
There must be one main funtion whereexecution begins when program is run.
This function is called the main
Int main (void)
{
.....................
}
Additional local functions and variables
-
8/2/2019 1_Introduction to C Programming
5/15
A simple C program
Program to display hello on in the console
#include
int main(void)
{
printf(hello\n);
}
The program created using any editor software
Eg gedit
-
8/2/2019 1_Introduction to C Programming
6/15
gedit
Start editing / typing the program by opening anew c file
Command gedit program_name
Eg gedit hello.c
After typing in the program save the program
The file hello.c Is called source which contains
the source code
-
8/2/2019 1_Introduction to C Programming
7/15
Compiling the program
After writing the source code we have toinvoke the compiler before running theprogram
Gcc compiler
Gcc program_name
Eg gcc hello.c or cc hello.c
The output file created is a.out
To run the out put file ./a.out
To redirect the output file from a.out
Gcc -o hello hello.c
Now the executable is hello instead of a.out
-
8/2/2019 1_Introduction to C Programming
8/15
Basic parts of the program #include
This includes header file stdio.h where all thestandard input output functions are defined
Function prototypes , datatypes, macros ,
inline functions and common definitions areincluded in header files.
Preprocessor insert this common definitionsto source files
-
8/2/2019 1_Introduction to C Programming
9/15
Preprocessor directive
Statements starting with # in the fisrt column iscalled preprocessor directive
#include directs preprocessor to include a
copy of the specified file
#define defines a macro. The preprocessorreplaces macro with original code whereverit is called.
-
8/2/2019 1_Introduction to C Programming
10/15
main()
Main is the main function of execution
When a program is made to run the main isexecuted
Subsequent functions are called from the mainfunction
Code of execution of main function as well assubfunctions are included in curlly brackets.
-
8/2/2019 1_Introduction to C Programming
11/15
Reserved Words (Keywords)
Keywords are that which have specialmeaning in C language
An identifier cannot have the same spellingand case as a C keyword
Eg int
main
char ..etc...
-
8/2/2019 1_Introduction to C Programming
12/15
Comments
Cooments are used to document the code
It is sequence of characters beginning with aforward slash asterisk combination (/*) andends with (*/)
Compiler consider it a s a single whitespaceand ignores
Single line comments can be made by //
A good programmers document his codewhile coding itself
-
8/2/2019 1_Introduction to C Programming
13/15
Identifiers
Identifiers or symbols are the names suppliedfor variables, types, functions, and labels inprogram.
Identifier names must differ in spelling andcase from any keywords
-
8/2/2019 1_Introduction to C Programming
14/15
Standard input and output
#include
int main()
{int a, b;
printf("enter twonumbers\n");
scanf("%d%d\n",&a,&b);printf(%d%d\n,a,b);
return 0
}
-
8/2/2019 1_Introduction to C Programming
15/15
Standard output function is printf
Standard output function is scanf
Their prototype is declared in stdio.h