Introduction toC Language
C is a general-purpose, structured, procedural
programming language developed by Dennis Ritchie (1972)
at Bell Laboratories.
It is widely used for system software, embedded systems,
operating systems, and compiler development due to its
efficiency, portability, and low-level memory access.
4.
Why LearnC Language?
Forms the foundation of many modern languages like C+
+, Java.
Helps understand memory management and hardware
interaction.
Simple syntax and powerful features.
5.
Features ofC Language
Simple and efficient
Structured programming
Portable (machine independent)
Rich set of operators
Supports low-level programming
Fast execution speed
6.
Applications ofC Language
Operating systems
Embedded systems
Compilers and interpreters
Device drivers
Database systems
Scientific and engineering applications
7.
Getting Startedwith C
C programs are written using a text editor, compiled using
a C compiler (e.g., GCC), and executed as machine code.
C follows a structured programming approach, dividing
programs into functions for better modularity and
readability.
8.
The CCharacter Set
The C character set includes:
Alphabets: A–Z, a–z
Digits: 0–9
Special Characters: + - * / % = < > ( ) { } [ ] ; , . _ #
White Spaces: space, tab, newline
9.
Constants, Variables,and Keywords
Constant: A fixed value that does not change during
program execution
Variable: A named memory location whose value can
change
Keyword: Reserved words with predefined meaning in C
Rules forConstructing Integer Constants
Must contain at least one digit
No decimal point allowed
Can be positive or negative
No spaces or commas
Examples: 25, -100, 0
12.
Rules forConstructing Real Constants
Must contain a decimal point
Can be positive or negative
No spaces allowed
Examples: 3.14, -0.25, 10.0
13.
Rules forConstructing Character Constants
Enclosed in single quotes
Contains only one character
Examples: 'A', '5', 'n'
14.
Types ofC Variables
Based on data types:
int – integer variables
float – decimal values
double – high-precision decimals
char – character data
15.
Rules forConstructing Variable Names
Must start with an alphabet or underscore
Can contain alphabets, digits, and underscore
Cannot use keywords
No special symbols or spaces
Case-sensitive
Examples: total, _sum, count1
16.
C Keywords
C has 32 reserved keywords, such as:
int, float, char, if, else, for, while, return, break, continue,
void
Keywords cannot be used as variable names.
17.
Structure ofa C Program
A C program is divided into different sections:
1. Documentation section
2. Link section
3. Definition section
4. Global declaration section
5. main() function
6. User-defined functions
20.
Input andOutput in C
Input and output are performed using standard functions.
Commonly used functions:
• scanf() – for input
• printf() – for output
21.
Receiving Input
C uses scanf() to take input from the user.
scanf("%d", &x);
& is the address operator
Format specifiers define data type
22.
C Instructions
C programs consist of instructions that perform actions.
Type Declaration Instruction
Used to declare variables before use.
int a;
float b;
[A] Point outthe errors, if any, in the following C statements:
(a) int = 314.562 * 150 ;
(b) name = ‘Ajay’ ;
(c) varchar = ‘3’ ;
(d) 3.14 * r * r * h = vol_of_cyl ;
(e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;
26.
[B] Evaluate thefollowing expressions and show
their hierarchy.
(a) g = big / 2 + big * 4 / big - big + abc / 3 ; (abc = 2.5,
big = 2, assume g to be a float)
27.
(b) on =ink * act / 2 + 3 / 2 * act + 2 + tig ; (ink = 4, act = 1,
tig = 3.2, assume on to be an int)
28.
(c) s =qui * add / 4 - 6 / 2 + 2 / 3 * 6 / god ; (qui = 4,
add = 2, god = 2, assume s to be an int)
29.
What wouldbe the output of the following programs:
(1) main( )
{
int i = 2, j = 3, k, l ;
float a, b ;
k = i / j * j ;
l = j / i * i ;
a = i / j * j ;
b = j / i * i ;
printf( "%d %d %f %f", k, l, a, b ) ; }
30.
(2) main( )
{
floata = 5, b = 2 ;
int c ;
c = a % b ;
printf ( "%d", c ) ;
}