Basics of C porgramming

29

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

Basics of C Program

Niyaz

[email protected]

tweetboy

niyazsky

9746 049 048

in/niyazsky

Page 4: Basics of C porgramming

Info about CC is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972.

The Unix operating system and virtually all Unix applications are written in the C language. C has now become a widely used professional language for various reasons.

• Easy to learn• Structured language• It produces efficient programs.• It can handle low-level activities.• It can be compiled on a variety of computers

Page 5: Basics of C porgramming

Facts about C Language• C was invented to write an operating system called UNIX.• C is a successor of B language which was introduced around 1970• The language was formalized in 1988 by the American National Standard Institue

(ANSI).• By 1973 UNIX OS almost totally written in C.• Today C is the most widely used System Programming Language.• Most of the state of the art software have been implemented using C

Note the followings C is a case sensitive programming language. It means in C printf and Printf will have

different meanings. C has a free-form line structure. End of each C statement must be marked with a

semicolon. Multiple statements can be one the same line. White Spaces (ie tab space and space bar ) are ignored. Statements can continue over multiple lines.

Page 6: Basics of C porgramming

C Program Token

KeyWords Constants Strings

Identifers Special Symbols

Operators

In a C source program, the basic element recognized by the compiler is the "token." A token is source-program text that the compiler does not break down into component elements.

Page 7: Basics of C porgramming

Sample C Program Code

#include<stdio.h>void main()

{int A,B,C;printf("Enter the two number\n");scanf("%d %d",&A,&B); C=A+B;printf("%d\n",C);

}

Page 8: Basics of C porgramming

KEYWORDS

Keywords are the base building block of any Computer Language.Keywords tells to the compiler of the Language what Programmer meant.

auto double int struct

break else long switch

case enum register typedef

char extern return union

const float short unsigned

continue for signed void

default goto sizeof volatile

do if static while

Page 9: Basics of C porgramming

Identifiers

The name of Variable,Functions,Labels and various other user defined items are Called identifier. The length of these identifier can vary from one to several character.

Rules for Identifiers

First character must be in alphabet or underscore. Must consist of only letters, digits or underscore. Only first 31 character are significant. Cannot use a Keyword. Must not contain white Space

Page 10: Basics of C porgramming

ConstantsIts an Variable that says the same once declared and cannot be change at run time.

String

A string is a Sequence of Character enclosed in double quotes.

OperatorsAn Operators is a symbol that tells the computer to Perform certain mathematical or Logical operations.

Special SymbolsSpace + - * / ^ \ () [] {} = != <> ‘ “ $ , ; : % ! & ? _ # <= >= @

Page 11: Basics of C porgramming

DATA TYPES in C LanguageC has a concept of 'data types' which are used to define a variable before its use. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location. The value of a variable can be changed any time.

C has the following basic built-in datatypes int float double char

Page 12: Basics of C porgramming

Format Specifiers

Format SpecifiersThere are many format specifiers defined in C. Take a look at the following list

Format Specifiers Using for

%i or %d int

%c Char

%f Float

%lf Double

%s String

Page 13: Basics of C porgramming

Sample C Program Code

#include<stdio.h>void main()

{int A,B,C;printf("Enter the two number\n");scanf("%d %d",&A,&B); C=A+B;printf("%d\n",C);

}

Page 14: Basics of C porgramming

Understanding the Execution

Page 15: Basics of C porgramming

Decision Making StatementsStatement Description

if statement An if statement consists of a boolean expression followed by one or more statements.

if...else statement An if statement can be followed by an optional else statement, which executes when the boolean expression is false.

nested if statements You can use one if or else if statement inside another if or else if statement(s).

switch statement A switch statement allows a variable to be tested for equality against a list of values.

nested switch statements You can use one swicth statement inside another switchstatement(s).

Page 16: Basics of C porgramming

Problem Statement

If Statement

Enter a number & Check whether its Less than 100?

Page 17: Basics of C porgramming

If Statement#include <stdio.h> int main (){ /* local variable definition */ int a = 10; /* check the boolean condition using if statement */ if( a < 20 ) { /* if condition is true then print the following */ printf("a is less than 20\n" ); } printf("value of a is : %d\n", a); return 0;}

Page 18: Basics of C porgramming

Problem Statement

If Else Statement

Find a Person can do Vote in Election? based on Age.

Page 19: Basics of C porgramming

If else statement

#include <stdio.h> int main (){ /* local variable definition */ int a = 100; /* check the boolean condition */ if( a < 20 ) { /* if condition is true then print the following */ printf("a is less than 20\n" ); } else { /* if condition is false then print the following */ printf("a is not less than 20\n" ); } printf("value of a is : %d\n", a); return 0;}

Page 20: Basics of C porgramming

Problem Statement

Switch Statement

Selecting new language in Mobile?

Page 21: Basics of C porgramming

Switch Statement#include <stdio.h> int main (){ /* local variable definition */ char grade = 'B';

switch(grade) { case 'A' : printf("Excellent!\n" ); break; case 'B' : printf("Well done\n" ); break; case 'D' : printf("You passed\n" ); break; case 'F' : printf("Better try again\n" ); break; default : printf("Invalid grade\n" ); } printf("Your grade is %c\n", grade ); return 0;}

Page 22: Basics of C porgramming

Loops

Loop Type Descriptionwhile loop Repeats a statement or group of statements until a given

condition is true. It tests the condition before executing the loop body.( First Check the Condition, If its true enter the Loop)

for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable (initialization, Condition, Increment or decrement)

do...while loop Like a while statement, except that it tests the condition at the end of the loop body. (Whatever the condition it execute at least once)

nested loops You can use one or more loop inside any another while, for or do..while loop (inside another loop)

Page 23: Basics of C porgramming

Problem Statement

For Loop

Enter and Display Student is Elite or Normal? Based on Fee

Page 24: Basics of C porgramming

For Loop

#include <stdio.h> int main (){ /* for loop execution */ for( int a = 10; a < 20; a = a + 1 ) { printf("value of a: %d\n", a); } return 0;}

Page 25: Basics of C porgramming

While Loop#include <stdio.h> int main (){ /* local variable definition */ int a = 10;

/* while loop execution */ while( a < 20 ) { printf("value of a: %d\n", a); a++; } return 0;}

Page 26: Basics of C porgramming

Array

An array is data structure (type of memory layout) that stores a collection of individual values that are of the same data type.

Page 27: Basics of C porgramming

Problem Statement

Array

Enter Roll No and Mark of Students and Display it?

(0) 10001 56 (1)

(1) 10002 46 (2)

(2) 10003 67 (3)

(3) 10004 47 (4)

Click for Program

Page 28: Basics of C porgramming

QUESTIONS SECTION

Page 29: 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