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
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
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.
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.
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);
}
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
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
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 + - * / ^ \ () [] {} = != <> ‘ “ $ , ; : % ! & ? _ # <= >= @
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
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
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);
}
Understanding the Execution
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).
Problem Statement
If Statement
Enter a number & Check whether its Less than 100?
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;}
Problem Statement
If Else Statement
Find a Person can do Vote in Election? based on Age.
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;}
Problem Statement
Switch Statement
Selecting new language in Mobile?
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;}
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)
Problem Statement
For Loop
Enter and Display Student is Elite or Normal? Based on Fee
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;}
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;}
Array
An array is data structure (type of memory layout) that stores a collection of individual values that are of the same data type.
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
QUESTIONS SECTION
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