basics of c porgramming
DESCRIPTION
Basics of C porgrammingTRANSCRIPT
Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
Basic of C
Atheendrh [email protected] kakkoth
Execution of C Program
•Creating a program :An editor like notepad or word pad is used to create a C program. This file contains a source code which consists of executable code. save as .c
• Compiling the program :The next step is to compile the program. The code is compiled by using compiler. Compiler converts executable code to binary code
•Linking a program to library :The object code of a program is linked with libraries that are needed for execution of a program. The linker is used to link the program with libraries.
•Execution of program :The final executable file is then run by dos command prompt or by any other software.
TokensTokens are individual words marks in passage of text. In C, program the smallest individual units are known as C Tokens. C has Six types of Tokens. The Tokens are shown in figure
Tokens
• Keywords– These are reserved words of the C language. For example int, float, if, else, for, while etc.
• Identifiers– An Identifier is a sequence of letters and digits, but must
start with a letter. Underscore ( _ ) is treated as a letter. Identifiers are used to name variables, functions etc.
– Valid: Root, _getchar, __sin, x1, x2, x3, x_1, If
– Invalid: 324, short, price$, My Name
Tokens
• Constants– Constants like 13, ‘a’, 1.3e-5 etc.
• Strings– A sequence of characters enclosed in double
quotes as “…”. For example “13” is a string literal and not number 13. ‘a’ and “a” are different.
• Operators– Arithmetic operators like +, -, *, / ,% etc.– Logical operators like ||, &&, ! etc. and so on
Tokens
• special symbol: ~ ! @ # $ % ^ & * ( ) _ + { } [ ] - < > , . / ? \ | : ; " '
• White Spaces– Spaces, new lines, tabs, comments ( A sequence of
characters enclosed in /* and */ ) etc. These are used to separate the adjacent identifiers, kewords and constants.
Header file
Key word
IIdentifiers
Operators
Special symbol
Strings
Header file contains different predefined functions, which are required to run the program
Header File in C : Header file contains different predefined
functions, which are required to run the program. All header files should be included explicitly before main ( ) function
Assert.h Ctype.h Math.h
Process.h Stdio.h Stdlib.h
String.h Time.h Graphics.h
Followings are the some commonly used header files which plays a vital role in C programming :
Stdio.h
stdio.h refers to standard input/output header file. The functions which are declared in stdio.h are very popular.
scanf() -used to take input from the standard input stream
Printf() -prints to the standard output stream
Data Types in C :
Decision Making Statements
C program executes program sequentially. Sometimes, a program requires checking of certain conditions in program execution. These statements are called as 'Decision Making Statements' or 'Conditional Statements‘
• Followings are the different conditional statements used in C.
• If Statement• If-Else Statement
If Statement : This is a conditional statement used in C to
check condition or to control the flow of execution of statements.
Syntax:
if(condition) {
statements; }
If-Else Statement :This is also one of the most useful conditional
statement used in C to check conditions
Syntax: if(condition)
{ true statements;
} else
{ false statements;
}
Looping Statements A loop is used using condition. The repetition is
done until condition is true• Some common examples of this looping
statements are :• while loop• for loop
While loopIt is used to repeat a block of statements until
condition is true.
Syntax: while(condition) { statements; increment/decrement; }
For loop One of the most important feature of this loop is that
the three actions can be taken at a time like variable initilisation, condition checking and increment/decrement.
Syntax: for(initialisation; test-condition; incre/decre)
{statements;
}
#include <stdio.h> #include <conio.h> void main() { int a; for(i=0; i<=5; i++) { printf("\n"); }
If this presentation helped you, please visit our page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us