Basics of ‘C’
Programming
Presented By: Shamsul Husain Ansari
G. H. Raisoni Institute of Engineering & Technology, Nagpur
What is ‘C’?
C is a Procedure Oriented Programming language use for Game design,
Graphics, Enterprise Applications.
C is widely used language. It provides many features that are given below.
● Machine Independent
● High Speed
● Pointers
● Recursion
Header Files : Header files in C language Contains the set of predefined standard
library functions.
● #include<stdio.h> : It is used for perform input and output operations using
functions scanf() and printf().
● #include<math.h>: It is used to perform mathematical operations like sqrt(),
pow(), etc.
● #include<time.h>: It is used to perform functions related to date() and time().
● #include<fstream.h>: It is used to control the data to read from a file as an
input and data to write into the file as an output
● Example : #include<stdio.h>
Header files in ‘C’.
What is main in ‘C’.
A main is a predefined keyword or function in C. It is a special function that always starts
executing code from the ‘main’ having ‘int’ or ‘void’ as return data type. In other words, a main()
function is an entry point of the programming code to start its execution.
Syntax:
int main() {
//body of the code
return 0;
}
Basic Structure of C Program
Header file #include<stdio.h>
main function int main() {
Variable declaration int a=20;
Body printf(“The value of a is %d”,a);
return return 0;
}
Keywords & Identifiers in ‘C’
In C language identifiers are the names given to variables, constants, functions and user-
defined data.
Syntax : data_type variable_name;
Examples: int marks; //in Ram the 2 byte of memory allocate by the name of marks.
Keyword Identifier
Int
float
char
number
decimal
character
Data Types in ‘C'
C has various data types to store data in program. C program can store integer,
decimal number, character(alphabets), string(word or sentence), list etc.
Syntax : type variable_name;
Example1: int roll_no; // int used for storing integer value.
Example 2: float percentage; // float data type used for storing decimal
numbers.
Note: C is a case sensitive language. It matter whether an identifier such as variable
name, is UPPERCASE or lowercase.
Keyword Used Format Specifier Size (Bytes)
int “%d” 4
char “%c” 1
float “%f” 4
double “%lf” 8
The format specifiers are used in C for input and output purposes. Using this concept the compiler
can understand that what type of data is in a variable during taking input using scanf() function and
printing using printf() function.
C Input
In C programming, scanf() is one of the commonly used function to take input from the user.
The scanf() function read formatted input from the standard input such as keyboards.
Example:
#include<stdio.h>
int main() {
int age; // variable declaration of type integer.
char name[7];
scanf(“%d”, &age);
scanf(“%s”,name);
printf(“Age= %d”, age); // printf() function used to display the output to
the user.
return 0;
}
Note: & represent the memory address and &age denotes the memory address of age.
Operators in C
An operator is simply a symbol that is used to perform operations. There can be many type of
operations like arithmetic, logical, bitwise, etc.
Arithmetic Operator: An arithmetic operator perform mathematical operation such as addition,
subtraction, multiplication, division etc on numerical values.
Operator Meaning of Operator
+ Addition
- subtraction
* multiplication
/ division
& remainder after division (modulo division)
Example
#include<stdio.h>
int main() {
Int a = 6, b = 4, c;
c = a+b;
printf(“ADDITION: %d”,c);
c = a-b;
printf(“SUBTRACTION: %d”, c);
return 0;
}
Output: ADDITION: 10
SUBTRACTION: 2
Increment & Decrement Operators
C programming has two operator increment ++ and decrement - - to change the
value of an operand (constant or variable) by 1.
Operator Meaning of Operator
++ Increment the value by 1
– – Decrement the value by 1
#include<stdio.h>
int main() {
int a = 10, b = 5;
printf(“INCREMENT: %d”,++a);
printf(“DECREMENT: %d”, - - b );
return 0;
}
Relational Operators
A relational operator checks the relationship between two operands. If the relation
is true, it returns 1; if the relation is false, it return value 0.
Operator Meaning of Operator Example
== Equal to 5 == 3 return 0
> Greater than 5 > 3 return 1
< Less than 5 < 3 return 0
!= Not equal to 5!=3 return 1
>= Greater than or equal to 5>=3 return 1
<= Less than or equal to 5<=3 return 0
Example
#include<stdio.h>
int main() {
Int a = 5, b = 3;
printf(“Equal to: %d”, a==b);
printf(“Not Equal: %d”, a!=b);
return 0;
}
Output: Equal to: 0
Not Equal : 1
Logical Operators
An expression containing logical operator returns either 0 or 1 depending upon
whether expression results true or false. Logical operators are commonly used in
decision making in C Programming
Operator Meaning
&& Logical AND. True only if all the operand
are true.
|| Logical OR. True only if either one operand
is true.
! Logical NOT. Only if the operand is 0
Example
#include<stdio.h>
int main() {
int a = 5, b = 5, c=10, result;
result = (a == b) && (c > b);
printf("%dn", result);
result = (a != b) || (c > b);
printf("%dn", result);
result = !(a == b);
printf("%dn", result);
return 0;
}
Exercise
Char type
Integer type
Float type
Solution

Basic of C Programming | 2022 Updated | By Shamsul H. Ansari

  • 1.
    Basics of ‘C’ Programming PresentedBy: Shamsul Husain Ansari G. H. Raisoni Institute of Engineering & Technology, Nagpur
  • 2.
    What is ‘C’? Cis a Procedure Oriented Programming language use for Game design, Graphics, Enterprise Applications. C is widely used language. It provides many features that are given below. ● Machine Independent ● High Speed ● Pointers ● Recursion
  • 3.
    Header Files :Header files in C language Contains the set of predefined standard library functions. ● #include<stdio.h> : It is used for perform input and output operations using functions scanf() and printf(). ● #include<math.h>: It is used to perform mathematical operations like sqrt(), pow(), etc. ● #include<time.h>: It is used to perform functions related to date() and time(). ● #include<fstream.h>: It is used to control the data to read from a file as an input and data to write into the file as an output ● Example : #include<stdio.h> Header files in ‘C’.
  • 4.
    What is mainin ‘C’. A main is a predefined keyword or function in C. It is a special function that always starts executing code from the ‘main’ having ‘int’ or ‘void’ as return data type. In other words, a main() function is an entry point of the programming code to start its execution. Syntax: int main() { //body of the code return 0; }
  • 5.
    Basic Structure ofC Program Header file #include<stdio.h> main function int main() { Variable declaration int a=20; Body printf(“The value of a is %d”,a); return return 0; }
  • 6.
    Keywords & Identifiersin ‘C’ In C language identifiers are the names given to variables, constants, functions and user- defined data. Syntax : data_type variable_name; Examples: int marks; //in Ram the 2 byte of memory allocate by the name of marks. Keyword Identifier Int float char number decimal character
  • 7.
    Data Types in‘C' C has various data types to store data in program. C program can store integer, decimal number, character(alphabets), string(word or sentence), list etc. Syntax : type variable_name; Example1: int roll_no; // int used for storing integer value. Example 2: float percentage; // float data type used for storing decimal numbers. Note: C is a case sensitive language. It matter whether an identifier such as variable name, is UPPERCASE or lowercase.
  • 8.
    Keyword Used FormatSpecifier Size (Bytes) int “%d” 4 char “%c” 1 float “%f” 4 double “%lf” 8 The format specifiers are used in C for input and output purposes. Using this concept the compiler can understand that what type of data is in a variable during taking input using scanf() function and printing using printf() function.
  • 9.
    C Input In Cprogramming, scanf() is one of the commonly used function to take input from the user. The scanf() function read formatted input from the standard input such as keyboards. Example: #include<stdio.h> int main() { int age; // variable declaration of type integer. char name[7]; scanf(“%d”, &age); scanf(“%s”,name); printf(“Age= %d”, age); // printf() function used to display the output to the user. return 0; } Note: & represent the memory address and &age denotes the memory address of age.
  • 10.
    Operators in C Anoperator is simply a symbol that is used to perform operations. There can be many type of operations like arithmetic, logical, bitwise, etc. Arithmetic Operator: An arithmetic operator perform mathematical operation such as addition, subtraction, multiplication, division etc on numerical values. Operator Meaning of Operator + Addition - subtraction * multiplication / division & remainder after division (modulo division)
  • 11.
    Example #include<stdio.h> int main() { Inta = 6, b = 4, c; c = a+b; printf(“ADDITION: %d”,c); c = a-b; printf(“SUBTRACTION: %d”, c); return 0; } Output: ADDITION: 10 SUBTRACTION: 2
  • 12.
    Increment & DecrementOperators C programming has two operator increment ++ and decrement - - to change the value of an operand (constant or variable) by 1. Operator Meaning of Operator ++ Increment the value by 1 – – Decrement the value by 1 #include<stdio.h> int main() { int a = 10, b = 5; printf(“INCREMENT: %d”,++a); printf(“DECREMENT: %d”, - - b ); return 0; }
  • 13.
    Relational Operators A relationaloperator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it return value 0. Operator Meaning of Operator Example == Equal to 5 == 3 return 0 > Greater than 5 > 3 return 1 < Less than 5 < 3 return 0 != Not equal to 5!=3 return 1 >= Greater than or equal to 5>=3 return 1 <= Less than or equal to 5<=3 return 0
  • 14.
    Example #include<stdio.h> int main() { Inta = 5, b = 3; printf(“Equal to: %d”, a==b); printf(“Not Equal: %d”, a!=b); return 0; } Output: Equal to: 0 Not Equal : 1
  • 15.
    Logical Operators An expressioncontaining logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C Programming Operator Meaning && Logical AND. True only if all the operand are true. || Logical OR. True only if either one operand is true. ! Logical NOT. Only if the operand is 0
  • 16.
    Example #include<stdio.h> int main() { inta = 5, b = 5, c=10, result; result = (a == b) && (c > b); printf("%dn", result); result = (a != b) || (c > b); printf("%dn", result); result = !(a == b); printf("%dn", result); return 0; }
  • 17.
  • 18.