SlideShare a Scribd company logo
1 of 93
Download to read offline
C LANGUAGE BASICS
Shikha Gautam
ASSISTANT PROFESSOR
Dennis M. Ritchie
C is System Programming Language: it is useful for
writing system programs (interface between the hardware
and user application) like compiler, device driver, BIOS(Basic
input/output system), linker, assembler etc.
It is a robust language with rich set of built-in functions and
operators that can be used to write any complex program.
C is Structured Language: C supports functions that
enables easy maintainability of code, by breaking large file
into smaller modules.
A C program is basically a collection of built-in functions
that are supported by C library. C contains many built-in
memory management functions.
Characteristics Of C
The portability, efficiency, ability to access specific hardware
addresses and low run time demand on system resources
makes it a good choice for implementing O.S. and embedded
system applications.
Case sensitive language.
 C programs are fast, efficient, easy to debug(detects errors
quickly).
C also supports graphics programming.
It is as close to the machine as possible while it is almost
universally available for existing processor architectures.
There is at least one C compiler for almost every existent
architecture.
Characteristics Of C …
Turbo C
Dev C++
Netbeans
eclipse
Code::Blocks
CodeLite
C++ Builder
GNAT Programming Studio
IDEs FOR C
Type a program
Save it with .c extension – F2
Compile the program – This will generate an exe file
(executable) – alt+F9
Run the program (Actually the exe created out of
compilation will run and not the .c file) – ctrl+F9
Copy- Ctrl+insert
Cut- Shift+delete
Paste- Shift+insert
RUNNING A „C‟ PROGRAM
#include<stdio.h>
#include<conio.h>
Void main()
{
//comment
Executable statements
/* multiline comments
*/
}
PROGRAM STRUCTURE
Header File Section
Program to print Hello World.
#include<stdio.h>
#include<conio.h>
int main()
{
clrscr();
printf("Hello World");
getch();
return 0;
}
SIMPLE C PROGRAM
FILES USED IN C PROGRAMMING
Source File
(file with .c
extension)
Object File
(file with .o
extension)
Compiler
Header File
(file with .h
extension)
Linker
 The files that are specified in the include section is
called as header file.
 These are precompiled files that has some functions
defined in them.
 We can call those functions in our program by
supplying parameters.
 Some header files are “stdio.h”, “math.h”, “string.h”
and “conio.h” etc.
HEADER FILES
 When a file is executed, the start point is the main
function.
 Main function is the user-defined function.
 From main function the flow goes as per the
programmers choice.
 There may or may not be other functions written by
user in a program.
 Main function is compulsory for any C program.
MAIN FUNCTION
 Token is source-program text that the compiler does
not break down into component elements.
 Basic element recognized by the compiler is the
"token“.
C LANGUAGE TOKENS
C has 6 different types of tokens viz.
1. Keywords [e.g. float, int, while]
2. Identifiers: The term identifier is usually used for name of
variable, function or array etc. [e.g. sum, amount]
3. Constants: Constants are expressions with a fixed value.
[e.g. -25.6, 100]
4. Strings: Sequence of characters. [e.g. “IIT”, “year”]
5. Special Symbols: Symbols other than the Alphabets and
Digits and white-spaces. [e.g. @, #, {, }, [, ] ]
6. Operators [e.g. +, -, *]
TOKEN TYPES IN „C‟
 "Keywords" are words that have special meaning to
the C compiler.
 C Keywords are also called as Reserved words .
 Cannot be used as Variable Name.
 In C there are 32 keywords.
 All keywords are written in only lowercase.
THE KEYWORDS
 Identifiers are the names given to program elements such as
variables, array and functions. These are user defined names.
 Cannot use C keywords as identifiers.
 First character can only be an alphabet or underscore.
 It can contain letters, digits or underscore ( _ ).
 Must NOT contain white spaces in between.
 case-sensitive.
THE IDENTIFIERS
CASE SENSITIVITY
 C is a case sensitive language.
It matters whether an identifier, such as a variable
name, is uppercase or lowercase.
Example:
area
Area
AREA
ArEa
are all seen as different variables by the compiler.
VALIDITY OF IDENTIFIERS (EXAMPLES)
 Constants are entities with a fixed value. Value of constant is
known to the compiler at compile time.
CONSTANTS
CONSTANTS
Integer Type
Constants
Floating
Point type
Constants
Character
Type
Constants
String
Type
Constants
 Integer Constants
Some of the examples are 112, 0551 etc.
 The floating point Constants
The floating point constants such as 0.0083, -0.78, +67.89 etc.
 Character Constants
For example, „8‟, „a‟ , „i‟ , „=‟ etc.
 String Constants
For example, “0211”, “Stack Overflow” etc.
CONSTANTS EXAMPLES
DECLARATION
 Must be declared before use.
 A constant declaration specifies Type, Name and
the Value.
 A variable declaration specifies Type, Name and
possibly the Initial Value.
 When you declare a constant or a variable, the
compiler:
1. Reserves a memory location in which to store the
value of the constant or variable.
2. Associates the name of the constant or variable
with the memory location.
 Container to store the data.
 Variables names are the names given to memory locations.
x = a + b
z = 3(y - 5)
VARIABLES
20
Memory Cells
X 65209
DECLARING VARIABLES
 Before using a variable, you must give the compiler
some information about the variable; i.e., you must
declare it.
 Examples of variable declarations:
int length ;
float area ;
 Variables are not automatically initialized.
 Initializing variable: int rate = 5;
DATA TYPES IN C
•int, float, double, charPrimitive/ Primary
data-type
•Array, functions, pointers
Derived Data-type
•Structure, union, enum, typedefUser-defined Data-
type
•The void data type has no values .
Void
qualifier signed or unsigned may be applied to char
or any integer.
DATA TYPES : 1- INTEGER
 Declarations tell the compiler what variable
names will be used and what type of data each
can handle (store).
 Variables of integer type can be defined
- On separate lines:
int length;
int width;
unsigned int area;
- On the same line:
int length, width;
unsigned int area;
DATA TYPE: 2- CHARACTER
 Internally char is just a number
 Numerical value is associated with character.
 Variables of character type can be defined:
char x;
char x, y;
 Numeric value of character is stored in memory.
CODE:
char letter;
letter = 'C';
MEMORY:
letter
67
Question:
char ch= „A‟;
what is the difference between:
1. printf(“%c”, ch);
2. printf(“%d”, ch);
QUICK RESPONSE! 
DATA TYPES: 3- FLOATING-POINT
 A floating-point type is a number with a fractional
part
 Represent typically 32 bit = 4 byte real numbers.
 Available in different sizes (number of bytes): float,
double, and long double
 Size of
float  size of double  size of long double
 Variables of floating point type can be defined:
- double x;
- double x, y;
#include<stdio.h>
#include<conio.h>
int main()
{
int age;
float weight;
char gender;
age= 25;
weight= 55;
gender= 'F';
printf("%d %f %c", age, weight, gender);
getch();
return 0;
}
VARIABLE DECLARATION AND USAGE IN C
Types of operators
• Arithmetic Operators (+, -, *, /, %)
• Relational Operators (<, >, <=, >=, ==, !=)
• Logical Operators (&&, ||, !)
• Bitwise Operators (&, |)
• Assignment Operators (=)
• Increment/Decrement Operators.
• Conditional Operators.
OPERATORS & EXPRESSIONS IN C
 Used for performing numeric calculations
 Operator precedence
Some arithmetic operators act before others (i.e., multiplication before
addition)
 Use parenthesis when needed:
Example: Find the average of three variables a, b and c
 Do not use: a + b + c / 3
 Use: (a + b + c ) / 3
ARITHMETIC OPERATORS
ARITHMETIC OPERATORS
C operation Arithmetic
operator
Algebraic
expression
C expression
Addition + f + 7 f + 7
Subtraction - p – c p - c
Multiplication * bm b * m
Division / x / y x / y
Modulus % r mod s r % s
#include<stdio.h>
#include<conio.h>
int main()
{
int num1 = 10;
int num2 = 50;
int sum;
sum = num1+num2;
printf("sum of %d and %d is %d",num1,num2,sum);
getch();
return 0;
}
EXAMPLE
Write down a program to find subtraction of two numbers.
RULES OF OPERATOR PRECEDENCE
Operator(s) Operation(s) Order of evaluation
(precedence)
() Parentheses Evaluated First. If there are
several pairs of parentheses
are evaluated left to right.
*, /, or % Multiplication,
Division, Modulus
Evaluated Second. If there
are several, they are
evaluated left to right.
+ or - Addition and
Subtraction
Evaluated last. If there are
several, they are
evaluated left to right.
 Relational operator are used to compare two operands.
Operands may be variable, constant or expression.
• Relational operators return Boolean values:
 0 if relation is FALSE
 1 if relation is TRUE
RELATIONAL OPERATORS
Operator Meaning
< Is less than
<= Is less than equal to
> Is greater than
>= Is greater than equal to
== Equal to
!= is not equal to
 Example:
int x=44;
int y=12;
(x == y) // false... Returns 0
(x >= y) // true... Returns 1
(x != y) // true ... Returns 1
EXAMPLE OF RELATIONAL OPERATOR
main()
{
int a=10,b=20,c=30,d,e;
d=a>b;
e=b<=c;
printf(“%d %d”,d,e);
getch();
}
Output:-
0 1
 Logical Operators are used to create compound expressions
1. if ( (a == 1) && (b < 3) || (c == 1) ) etc.
 However, these can also be used in regular expressions
LOGICAL OPERATORS
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Operand-1
(Op1)
Operand-2
(Op2)
Op1 && Op2
(Logical AND)
Op1 | | Op2
(Logical OR)
1 1 1 1
1 0 0 1
0 1 0 1
0 0 0 0
LOGICAL OPERATOR- TRUTH TABLE
Condition NOT
0 1
1 0
 Assignment operator are used to assign the value or an
expression or a value of a variable to another variable
int x = 9;
 Some examples are::
x= x+y can be written as x+=y
a=a*(n+1) can be written as a *= n+1
z= z%d can be written as z%=d
ASSIGNMENT OPERATORS ( = )
a = 8
Expression
 In C, we have 2 very useful operators called the increment &
decrement operators:
 Increment : ++ adds 1 to the operand
 Decrement : -- subtracts 1 from the operand
INCREMENT/DECREMENT OPERATORS
Operator Meaning
++x Pre increment
- -x Pre decrement
x++ Post increment
X- - Post decrement
#include<stdio.h>
#include<conio.h>
int main()
{
int x=10;
printf("value of x is %dn",x++);
printf("value of x is %dn",x);
getch();
return 0;
}
EXAMPLE
 Used to test the conditions in the conditional expressions.
 Conditional expression
Format: <Expression 1> ? <Expression 2> : <Expression 3>
Example:
CONDITIONAL OPERATORS
Test Condition True expression False expression
x ? y : z
USE OF CONDITIONAL OPERATORS
Consider the following
statements:
a= 80;
b= 95;
if(a>b)
z=a;
else
z=b;
Now consider these
statements:
a=80;
b=95;
z= (a>b) ? a : b;
Both the statements are
resulting the same values.
This is an example of usage
of conditional expressions
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
BITWISE OPERATORS
 These operators are used by the programmer to
communicate directly with the hardware.
BITWISE OPERATORS
x : 1 0 1 0 (binary)
y : 1 1 0 0 (binary)
x & y : 1 0 0 0 (binary)
x | y : 1 1 1 0 (binary)
x ^ y : 0 1 1 0 (binary)
~x : 0 1 0 1 (binary)
 The sizeof operator is used with an operand to return the
number of bytes the operand occupies.
 It‟s a compile time operator.
 Also used to allocate memory spaces dynamically to different
variables while any program execution.
 For example::
k= sizeof (sum);
j= sizeof(long int);
w= sizeof(32767);
THE SIZE OF OPERATOR
1. Formatted Functions:
2. Unformatted Functions:
INPUT AND OUTPUT FUNCTIONS
 C executes program sequentially.
 C provides various key condition statements to check
conditions and execute statements according conditional
criteria.
 This statements are called decision making statements and
control statements.
CONDITIONS IN C PROGRAMMING
CONDITIONS IN C PROGRAMMING
DECISION CONTROL STATEMENT
 Decision control statement disrupt or alter the sequential
execution of the statement of the program depending on the
test condition in program.
Decision
control
statement
1. If
statement
3. Switch
statement
4. Go To
statement
2. If else
statement
 if Statement
Example: if Statement
 if...else Statement
Example: if...else Statement
 if...else Ladder
Example: if...else Ladder
 Nested if...else
Example: Nested if...else
C IF...ELSE STATEMENT
 The If statement is a powerful decision making statement and
is used to control the flow of execution of statement.
IF STATEMENT
condition
Block of if
Next statement
STOP
FALSE
TRUE
The syntax of if statement is:
if (testExpression)
{
// statement(s)
}
// statement(s)
EXAMPLE OF IF STATEMENT
#include<stdio.h>
#include<conio.h>
int main()
{
int age = 20;
if(age>= 18)
{
printf(" You are an adult");
}
getch();
return 0;
}
The if statement evaluates the test expression inside the
parenthesis.
 If the test expression is evaluated to true (nonzero),
statement(s) inside the body of if is executed.
 If the test expression is evaluated to false (0), statement(s)
inside the body of if is skipped from execution.
 If the condition is true the true block is execute otherwise
False block is execute.
IF-ELSE STATEMENT
condition
Block of if
Next statement
STOP
Block of else
FALSE
TRUE
if (testExpression)
{ // statement(s) inside the body of if
}
else
{
// statement(s) inside the body of else
}
EXAMPLE OF IF ELSE STATEMENT
#include<stdio.h>
#include<conio.h>
int main()
{
int age = 16;
if(age<= 18)
{
printf(" You are a minor");
}
else
{
printf(" You are an adult");
}
getch();
return 0;
}
IF...ELSE LADDER
(IF...ELSE IF....ELSE STATEMENT)
NESTED IF...ELSE
 Switch statement is a multi-way decision making statement
which selects one of the several alternative based on the value
of integer variable or expression.
SWITCH STATEMENT
EXAMPLE
#include<stdio.h>
#include<conio.h>
int main()
{
int number =2;
switch(number)
{
case 1: printf("onen");
break;
case 2: printf("twon");
break;
default : printf("defaultn");
}
getch();
return 0;
}
 A GO TO statement can cause program control to end up
anywhere in the program unconditionally.
GO TO STATEMENT
#include<stdio.h>
#include<conio.h>
int main()
{
int i=1;
up: printf("Hello to Cn ");
i++;
if(i<=5)
goto up ;
getch();
return 0;
}
UNIT -III
The break statement terminates the loop (for, while
and do...while loop) immediately when it is
encountered.
BREAK STATEMENT
 The continue statement skips statements after it
inside the loop.
CONTINUE STATEMENT
PROGRAMMING
EXAMPLES
C intro
C intro
C intro
C intro
C intro
C intro
C intro
C intro
C intro

More Related Content

What's hot (18)

Clanguage
ClanguageClanguage
Clanguage
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Pointers
PointersPointers
Pointers
 
C language ppt
C language pptC language ppt
C language ppt
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler design
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
C presentation
C presentationC presentation
C presentation
 

Similar to C intro

unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptxmadhurij54
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centrejatin batra
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptxsscprep9
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxMamataAnilgod
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptxRowank2
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language Rowank2
 
C prog ppt
C prog pptC prog ppt
C prog pptxinoe
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computerShankar Gangaju
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c languageAkshhayPatel
 

Similar to C intro (20)

C-PPT.pdf
C-PPT.pdfC-PPT.pdf
C-PPT.pdf
 
C introduction
C introductionC introduction
C introduction
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
Pc module1
Pc module1Pc module1
Pc module1
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptx
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
C material
C materialC material
C material
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
Fundamentals of c language
Fundamentals of c languageFundamentals of c language
Fundamentals of c language
 

More from SHIKHA GAUTAM

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionSHIKHA GAUTAM
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance SHIKHA GAUTAM
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in cSHIKHA GAUTAM
 
3. basic organization of a computer
3. basic organization of a computer3. basic organization of a computer
3. basic organization of a computerSHIKHA GAUTAM
 
Generations of computer
Generations of computerGenerations of computer
Generations of computerSHIKHA GAUTAM
 
Warehouse Planning and Implementation
Warehouse Planning and ImplementationWarehouse Planning and Implementation
Warehouse Planning and ImplementationSHIKHA GAUTAM
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and BasicsSHIKHA GAUTAM
 

More from SHIKHA GAUTAM (15)

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit ii_KCS201
Unit ii_KCS201Unit ii_KCS201
Unit ii_KCS201
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in c
 
4. algorithm
4. algorithm4. algorithm
4. algorithm
 
3. basic organization of a computer
3. basic organization of a computer3. basic organization of a computer
3. basic organization of a computer
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
c_programming
c_programmingc_programming
c_programming
 
Data Mining
Data MiningData Mining
Data Mining
 
Warehouse Planning and Implementation
Warehouse Planning and ImplementationWarehouse Planning and Implementation
Warehouse Planning and Implementation
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and Basics
 
DBMS
DBMSDBMS
DBMS
 

Recently uploaded

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 

Recently uploaded (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 

C intro

  • 1. C LANGUAGE BASICS Shikha Gautam ASSISTANT PROFESSOR Dennis M. Ritchie
  • 2. C is System Programming Language: it is useful for writing system programs (interface between the hardware and user application) like compiler, device driver, BIOS(Basic input/output system), linker, assembler etc. It is a robust language with rich set of built-in functions and operators that can be used to write any complex program. C is Structured Language: C supports functions that enables easy maintainability of code, by breaking large file into smaller modules. A C program is basically a collection of built-in functions that are supported by C library. C contains many built-in memory management functions. Characteristics Of C
  • 3. The portability, efficiency, ability to access specific hardware addresses and low run time demand on system resources makes it a good choice for implementing O.S. and embedded system applications. Case sensitive language.  C programs are fast, efficient, easy to debug(detects errors quickly). C also supports graphics programming. It is as close to the machine as possible while it is almost universally available for existing processor architectures. There is at least one C compiler for almost every existent architecture. Characteristics Of C …
  • 4.
  • 6. Type a program Save it with .c extension – F2 Compile the program – This will generate an exe file (executable) – alt+F9 Run the program (Actually the exe created out of compilation will run and not the .c file) – ctrl+F9 Copy- Ctrl+insert Cut- Shift+delete Paste- Shift+insert RUNNING A „C‟ PROGRAM
  • 7.
  • 8. #include<stdio.h> #include<conio.h> Void main() { //comment Executable statements /* multiline comments */ } PROGRAM STRUCTURE Header File Section
  • 9.
  • 10.
  • 11.
  • 12. Program to print Hello World. #include<stdio.h> #include<conio.h> int main() { clrscr(); printf("Hello World"); getch(); return 0; } SIMPLE C PROGRAM
  • 13. FILES USED IN C PROGRAMMING Source File (file with .c extension) Object File (file with .o extension) Compiler Header File (file with .h extension) Linker
  • 14.  The files that are specified in the include section is called as header file.  These are precompiled files that has some functions defined in them.  We can call those functions in our program by supplying parameters.  Some header files are “stdio.h”, “math.h”, “string.h” and “conio.h” etc. HEADER FILES
  • 15.  When a file is executed, the start point is the main function.  Main function is the user-defined function.  From main function the flow goes as per the programmers choice.  There may or may not be other functions written by user in a program.  Main function is compulsory for any C program. MAIN FUNCTION
  • 16.  Token is source-program text that the compiler does not break down into component elements.  Basic element recognized by the compiler is the "token“. C LANGUAGE TOKENS
  • 17. C has 6 different types of tokens viz. 1. Keywords [e.g. float, int, while] 2. Identifiers: The term identifier is usually used for name of variable, function or array etc. [e.g. sum, amount] 3. Constants: Constants are expressions with a fixed value. [e.g. -25.6, 100] 4. Strings: Sequence of characters. [e.g. “IIT”, “year”] 5. Special Symbols: Symbols other than the Alphabets and Digits and white-spaces. [e.g. @, #, {, }, [, ] ] 6. Operators [e.g. +, -, *] TOKEN TYPES IN „C‟
  • 18.  "Keywords" are words that have special meaning to the C compiler.  C Keywords are also called as Reserved words .  Cannot be used as Variable Name.  In C there are 32 keywords.  All keywords are written in only lowercase. THE KEYWORDS
  • 19.
  • 20.  Identifiers are the names given to program elements such as variables, array and functions. These are user defined names.  Cannot use C keywords as identifiers.  First character can only be an alphabet or underscore.  It can contain letters, digits or underscore ( _ ).  Must NOT contain white spaces in between.  case-sensitive. THE IDENTIFIERS
  • 21. CASE SENSITIVITY  C is a case sensitive language. It matters whether an identifier, such as a variable name, is uppercase or lowercase. Example: area Area AREA ArEa are all seen as different variables by the compiler.
  • 23.  Constants are entities with a fixed value. Value of constant is known to the compiler at compile time. CONSTANTS CONSTANTS Integer Type Constants Floating Point type Constants Character Type Constants String Type Constants
  • 24.  Integer Constants Some of the examples are 112, 0551 etc.  The floating point Constants The floating point constants such as 0.0083, -0.78, +67.89 etc.  Character Constants For example, „8‟, „a‟ , „i‟ , „=‟ etc.  String Constants For example, “0211”, “Stack Overflow” etc. CONSTANTS EXAMPLES
  • 25. DECLARATION  Must be declared before use.  A constant declaration specifies Type, Name and the Value.  A variable declaration specifies Type, Name and possibly the Initial Value.  When you declare a constant or a variable, the compiler: 1. Reserves a memory location in which to store the value of the constant or variable. 2. Associates the name of the constant or variable with the memory location.
  • 26.  Container to store the data.  Variables names are the names given to memory locations. x = a + b z = 3(y - 5) VARIABLES 20 Memory Cells X 65209
  • 27. DECLARING VARIABLES  Before using a variable, you must give the compiler some information about the variable; i.e., you must declare it.  Examples of variable declarations: int length ; float area ;  Variables are not automatically initialized.  Initializing variable: int rate = 5;
  • 28. DATA TYPES IN C •int, float, double, charPrimitive/ Primary data-type •Array, functions, pointers Derived Data-type •Structure, union, enum, typedefUser-defined Data- type •The void data type has no values . Void
  • 29.
  • 30. qualifier signed or unsigned may be applied to char or any integer.
  • 31. DATA TYPES : 1- INTEGER  Declarations tell the compiler what variable names will be used and what type of data each can handle (store).  Variables of integer type can be defined - On separate lines: int length; int width; unsigned int area; - On the same line: int length, width; unsigned int area;
  • 32. DATA TYPE: 2- CHARACTER  Internally char is just a number  Numerical value is associated with character.  Variables of character type can be defined: char x; char x, y;  Numeric value of character is stored in memory. CODE: char letter; letter = 'C'; MEMORY: letter 67
  • 33. Question: char ch= „A‟; what is the difference between: 1. printf(“%c”, ch); 2. printf(“%d”, ch); QUICK RESPONSE! 
  • 34. DATA TYPES: 3- FLOATING-POINT  A floating-point type is a number with a fractional part  Represent typically 32 bit = 4 byte real numbers.  Available in different sizes (number of bytes): float, double, and long double  Size of float  size of double  size of long double  Variables of floating point type can be defined: - double x; - double x, y;
  • 35.
  • 36. #include<stdio.h> #include<conio.h> int main() { int age; float weight; char gender; age= 25; weight= 55; gender= 'F'; printf("%d %f %c", age, weight, gender); getch(); return 0; } VARIABLE DECLARATION AND USAGE IN C
  • 37. Types of operators • Arithmetic Operators (+, -, *, /, %) • Relational Operators (<, >, <=, >=, ==, !=) • Logical Operators (&&, ||, !) • Bitwise Operators (&, |) • Assignment Operators (=) • Increment/Decrement Operators. • Conditional Operators. OPERATORS & EXPRESSIONS IN C
  • 38.  Used for performing numeric calculations  Operator precedence Some arithmetic operators act before others (i.e., multiplication before addition)  Use parenthesis when needed: Example: Find the average of three variables a, b and c  Do not use: a + b + c / 3  Use: (a + b + c ) / 3 ARITHMETIC OPERATORS
  • 39. ARITHMETIC OPERATORS C operation Arithmetic operator Algebraic expression C expression Addition + f + 7 f + 7 Subtraction - p – c p - c Multiplication * bm b * m Division / x / y x / y Modulus % r mod s r % s
  • 40. #include<stdio.h> #include<conio.h> int main() { int num1 = 10; int num2 = 50; int sum; sum = num1+num2; printf("sum of %d and %d is %d",num1,num2,sum); getch(); return 0; } EXAMPLE Write down a program to find subtraction of two numbers.
  • 41. RULES OF OPERATOR PRECEDENCE Operator(s) Operation(s) Order of evaluation (precedence) () Parentheses Evaluated First. If there are several pairs of parentheses are evaluated left to right. *, /, or % Multiplication, Division, Modulus Evaluated Second. If there are several, they are evaluated left to right. + or - Addition and Subtraction Evaluated last. If there are several, they are evaluated left to right.
  • 42.  Relational operator are used to compare two operands. Operands may be variable, constant or expression. • Relational operators return Boolean values:  0 if relation is FALSE  1 if relation is TRUE RELATIONAL OPERATORS Operator Meaning < Is less than <= Is less than equal to > Is greater than >= Is greater than equal to == Equal to != is not equal to
  • 43.  Example: int x=44; int y=12; (x == y) // false... Returns 0 (x >= y) // true... Returns 1 (x != y) // true ... Returns 1
  • 44. EXAMPLE OF RELATIONAL OPERATOR main() { int a=10,b=20,c=30,d,e; d=a>b; e=b<=c; printf(“%d %d”,d,e); getch(); } Output:- 0 1
  • 45.  Logical Operators are used to create compound expressions 1. if ( (a == 1) && (b < 3) || (c == 1) ) etc.  However, these can also be used in regular expressions LOGICAL OPERATORS Operator Meaning && Logical AND || Logical OR ! Logical NOT
  • 46. Operand-1 (Op1) Operand-2 (Op2) Op1 && Op2 (Logical AND) Op1 | | Op2 (Logical OR) 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 0 LOGICAL OPERATOR- TRUTH TABLE Condition NOT 0 1 1 0
  • 47.  Assignment operator are used to assign the value or an expression or a value of a variable to another variable int x = 9;  Some examples are:: x= x+y can be written as x+=y a=a*(n+1) can be written as a *= n+1 z= z%d can be written as z%=d ASSIGNMENT OPERATORS ( = ) a = 8 Expression
  • 48.  In C, we have 2 very useful operators called the increment & decrement operators:  Increment : ++ adds 1 to the operand  Decrement : -- subtracts 1 from the operand INCREMENT/DECREMENT OPERATORS Operator Meaning ++x Pre increment - -x Pre decrement x++ Post increment X- - Post decrement
  • 49. #include<stdio.h> #include<conio.h> int main() { int x=10; printf("value of x is %dn",x++); printf("value of x is %dn",x); getch(); return 0; } EXAMPLE
  • 50.  Used to test the conditions in the conditional expressions.  Conditional expression Format: <Expression 1> ? <Expression 2> : <Expression 3> Example: CONDITIONAL OPERATORS Test Condition True expression False expression x ? y : z
  • 51. USE OF CONDITIONAL OPERATORS Consider the following statements: a= 80; b= 95; if(a>b) z=a; else z=b; Now consider these statements: a=80; b=95; z= (a>b) ? a : b; Both the statements are resulting the same values. This is an example of usage of conditional expressions
  • 52.
  • 53. Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise XOR BITWISE OPERATORS  These operators are used by the programmer to communicate directly with the hardware.
  • 54. BITWISE OPERATORS x : 1 0 1 0 (binary) y : 1 1 0 0 (binary) x & y : 1 0 0 0 (binary) x | y : 1 1 1 0 (binary) x ^ y : 0 1 1 0 (binary) ~x : 0 1 0 1 (binary)
  • 55.  The sizeof operator is used with an operand to return the number of bytes the operand occupies.  It‟s a compile time operator.  Also used to allocate memory spaces dynamically to different variables while any program execution.  For example:: k= sizeof (sum); j= sizeof(long int); w= sizeof(32767); THE SIZE OF OPERATOR
  • 56. 1. Formatted Functions: 2. Unformatted Functions: INPUT AND OUTPUT FUNCTIONS
  • 57.
  • 58.  C executes program sequentially.  C provides various key condition statements to check conditions and execute statements according conditional criteria.  This statements are called decision making statements and control statements. CONDITIONS IN C PROGRAMMING
  • 59. CONDITIONS IN C PROGRAMMING
  • 60. DECISION CONTROL STATEMENT  Decision control statement disrupt or alter the sequential execution of the statement of the program depending on the test condition in program. Decision control statement 1. If statement 3. Switch statement 4. Go To statement 2. If else statement
  • 61.  if Statement Example: if Statement  if...else Statement Example: if...else Statement  if...else Ladder Example: if...else Ladder  Nested if...else Example: Nested if...else C IF...ELSE STATEMENT
  • 62.  The If statement is a powerful decision making statement and is used to control the flow of execution of statement. IF STATEMENT condition Block of if Next statement STOP FALSE TRUE
  • 63. The syntax of if statement is: if (testExpression) { // statement(s) } // statement(s)
  • 64. EXAMPLE OF IF STATEMENT #include<stdio.h> #include<conio.h> int main() { int age = 20; if(age>= 18) { printf(" You are an adult"); } getch(); return 0; }
  • 65. The if statement evaluates the test expression inside the parenthesis.  If the test expression is evaluated to true (nonzero), statement(s) inside the body of if is executed.  If the test expression is evaluated to false (0), statement(s) inside the body of if is skipped from execution.
  • 66.  If the condition is true the true block is execute otherwise False block is execute. IF-ELSE STATEMENT condition Block of if Next statement STOP Block of else FALSE TRUE
  • 67. if (testExpression) { // statement(s) inside the body of if } else { // statement(s) inside the body of else }
  • 68.
  • 69. EXAMPLE OF IF ELSE STATEMENT #include<stdio.h> #include<conio.h> int main() { int age = 16; if(age<= 18) { printf(" You are a minor"); } else { printf(" You are an adult"); } getch(); return 0; }
  • 71.
  • 73.  Switch statement is a multi-way decision making statement which selects one of the several alternative based on the value of integer variable or expression. SWITCH STATEMENT
  • 74.
  • 75. EXAMPLE #include<stdio.h> #include<conio.h> int main() { int number =2; switch(number) { case 1: printf("onen"); break; case 2: printf("twon"); break; default : printf("defaultn"); } getch(); return 0; }
  • 76.
  • 77.
  • 78.
  • 79.  A GO TO statement can cause program control to end up anywhere in the program unconditionally. GO TO STATEMENT
  • 80. #include<stdio.h> #include<conio.h> int main() { int i=1; up: printf("Hello to Cn "); i++; if(i<=5) goto up ; getch(); return 0; }
  • 82. The break statement terminates the loop (for, while and do...while loop) immediately when it is encountered. BREAK STATEMENT
  • 83.  The continue statement skips statements after it inside the loop. CONTINUE STATEMENT