Basics of C porgramming

20

description

Basics of C porgramming

Transcript of Basics of C porgramming

Page 1: Basics of C porgramming
Page 2: Basics of C porgramming

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

Page 3: Basics of C porgramming

Basic of C

Atheendrh [email protected] kakkoth

Page 4: Basics of C porgramming

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.

Page 5: Basics of C porgramming

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

Page 6: Basics of C porgramming

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

Page 7: Basics of C porgramming

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

Page 8: Basics of C porgramming

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.

Page 9: Basics of C porgramming

Header file

Key word

IIdentifiers

Operators

Special symbol

Strings

Header file contains different predefined functions, which are required to run the program

Page 11: Basics of C porgramming

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

Page 12: Basics of C porgramming

Data Types in C :

Page 13: Basics of C porgramming

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

Page 14: Basics of C porgramming

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; }

Page 15: Basics of C porgramming

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;

}

Page 16: Basics of C porgramming

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

Page 17: Basics of C porgramming

While loopIt is used to repeat a block of statements until

condition is true.

Syntax: while(condition) { statements; increment/decrement; }

Page 18: Basics of C porgramming

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"); }

Page 19: Basics of C porgramming

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

Page 20: Basics of C porgramming

Contact Us