Beruflich Dokumente
Kultur Dokumente
Programming in C
2
Identifiers
• Identifiers are name that are given to various program
elements, such as variables,functions and arrays.
• Identifiers consist of letters and digits in any order except
that the first character must be a letter.
• Both uppercase and lowercase letters are not
interchangeable.
• Underscore is often used in the middle of an identifier. It
may also begin with underscore.
Programming in C
3
Keywords
• There are certain reserve words called keywords that have a
standard predefined meaning.
• Keywords can be used only for their intended purpose; they cannot
be used as programmer defined identifiers.
Programming in C
4
Data Types
• C data types are defined as the data storage format that a variable
can store a data to perform a specific operation.
• Data types are used to define a variable before to use in a program.
• Size of variable, constant and array are determined by data types.
• There are four data types in C language. They are,
Programming in C
5
Integer data type
Programming in C 6
Character data type
Programming in C 7
Floating point data type
Programming in C 8
Qualifier
• Qualifier is an extra name given to variables, showing an extra
quality or extra meaning for that variable or function. like Dr in Dr
Arun Kumar.
• Qualifiers are : signed, unsigned, long, short, long
long, const, static, auto, extern, register
Programming in C
9
Programming in C
10
Programming in C
11
Variables
• C variable is a named location in a memory where a program can
manipulate the data. This location is used to hold the value of the variable.
• The value of the C variable may get change in the program.
• C variable might be belonging to any of the data type like int, float, char etc.
Programming in C
12
Rules for naming C variable:
Programming in C 13
Declaring & initializing C variable
Programming in C 14
Types of variables in C
There are three types of variables in C program They are,
• Local variable
• Global variable
Programming in C 15
Global Variables
Programming in C 16
Local Variables
• The scope of local variables will be within
the function only.
• These variables are declared within the
function and can’t be accessed outside the
function.
Programming in C 17
Printing Out and Inputting variable
• printf()
• scanf()
• printf() and scanf() functions are inbuilt library functions
in C which are available in C library by default. These
functions are declared and related macros are defined in
“stdio.h” which is a header file.
• We have to include “stdio.h” file as shown in below C
program to make use of these printf() and scanf() library
functions.
Programming in C 18
printf()
• we can print the data or user defined message on console or monitor.
• While working with printf(), it can take any number of arguments but first argument
must be within the double cotes (" ") and every argument should separated with
comma ( , ) Within the double cotes, whatever we pass, it prints same, if any format
specifies are there, then that copy the type of value. The scientific name of the
monitor is called console.
• Syntax is as follows-
printf("user defined message");
or
prinf("Format specifers",value1,value2,..);
Programming in C 19
Format specifier
Programming in C 20
Example of printf()
int a=10;
double d=13.4;
printf("%f%d",d,a);
Programming in C 21
scanf()
• scanf() is a predefined function in "stdio.h"
header file. It can be used to read the
input value from the keyword.
• Syntax-
scanf("format specifiers",&value1,&value2,.....);
Programming in C 22
Example of scanf()
int a;
float b;
scanf("%d%f",&a,&b);
Programming in C 23
Constants
C Constants are also like normal variables. But, only difference
is, their values can not be modified by the program once they are
defined.
• Constants refer to fixed values. They are also called as literals.
• Constants may be belonging to any of the data type.
• There are four basic types of constants in C.
• They are integer constants, floating point constants, character
constants, character constants and string constants and
enumeration constants.
• Syntax:
const data_type variable_name; (or) const data_type
*variable_name;
Programming in C
24
Types of C constant
• Integer constants
• Real or Floating point constants
• Octal & Hexadecimal constants
• Character constants
• String constants
• Backslash character constants
Programming in C 25
sizeof() function in C
Programming in C 26
Operators and Expression
• An operator is a symbol that tells the computer
to perform certain mathematical and logical
manipulations.
• Operators are used in programs to manipulate
data variables. They usually form a part of
expressions.
• An expression is a sequence of operands and
operators that reduces to a single value.
27
Programming in C
Types of Operators
• C operators can be classified into a number of
categories.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Increment and Decrement Operators
6. Conditional Operator
7. Bitwise Operators
Programming in C 28
Arithmetic Operators
C Arithmetic operators are used to perform mathematical
calculations like addition, subtraction, multiplication, division and
modulus in C programs.
Programming in C 29
Programming in C 30
Relational Operator
Relational operators are used to find the relation between two
variables. i.e. to compare the values of two variables in a C program.
Programming in C 31
Programming in C 32
Logical Operators
• These operators are used to perform logical operations on the given expressions.
• There are 3 logical operators in C language. They are, logical AND (&&), logical OR
(||) and logical NOT (!).
Programming in C 33
Programming in C 34
Assignment Operator
Programming in C 35
Bitwise Operator
• These operators are used to perform bit operations. Decimal values are
converted into binary values which are the sequence of bits and bit wise
operators work on these bits.
• Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~
(bitwise OR), ^ (XOR), << (left shift) and >> (right shift).
Programming in C 36
Programming in C 37
Increment and Decrement Operator
Programming in C 40
• #include <stdio.h>
int main()
{
int x=1, y ;
y = ( x ==1 ? 2 : 0 ) ;
printf(“x value is %d\n”, x);
printf(“y value is %d”, y);
}
Programming in C 41
Programming in C 42
C – Decision Control statement
Programming in C 43
“If”, “else” and “nested if” decision control
statements in C
Programming in C 44
Flow Chart of if statement
Programming in C 45
Flow Chart of if else statement
Programming in C 46
Flow Chart of Nested if statement
Programming in C 47
Flow Chart of if else ladder statement
Programming in C 48
Programming in C 49
Programming in C 50
Programming in C 51
C – Loop control statements
Programming in C 52
Programming in C 53
Flow Chart of while statement
Programming in C 54
Flow Chart of do while statement
Programming in C 55
Flow Chart of for statement
Programming in C 56
Programming in C 57
Programming in C 58
Programming in C 59
Difference between while & do while loops in C
Programming in C 60