C प्रोग्रामिंग में स्टेटमेंट्स को उनके काम के आधार पर अलग-अलग श्रेणियों में बाँटा जाता है।
नीचे इसका सरल विवरण दिया गया है:
स्टेटमेंट का प्रकार
उदाहरण
उद्देश्य
घोषणा (Declaration)
int x;
वेरिएबल्स के
लिए मेमोरी सुरक्षित करना
इनपुट/आउटपुट
(Input/Output)
printf(), scanf()
इनपुट लेना
और आउटपुट दिखाना
एक्सप्रेशन (Expression)
x = y + 5;
गणनाएँ/ऑपरेशन
करना
शर्तीय (Conditional)
if, switch
निर्णय लेना
लूप (Looping)
for, while
कार्य को
दोहराना
जंप (Jump)
break, continue, return, goto
प्रोग्राम के
किसी अन्य भाग पर जाना
1. घोषणा (Declaration) स्टेटमेंट्स
ये स्टेटमेंट्स वेरिएबल, कॉन्स्टेंट, एरे या फंक्शन को प्रोग्राम में उपयोग करने से पहले घोषित करने के लिए होते हैं।
ये कंपाइलर को बताते हैं:
डाटा का नाम
डाटा का प्रकार (integer, float, char आदि)
कभी-कभी शुरुआती मान (initial value)
सिंटैक्स:
data_type variable_name;
या
data_type variable_name = value;
उदाहरण:
int age; // integer वेरिएबल की घोषणाfloat price; // float वेरिएबल की घोषणाchar grade; // char वेरिएबल की घोषणाint rollNo = 101; // घोषणा और प्रारंभिक मानconstint MAX = 100; // कॉन्स्टेंट की घोषणा
💡 ये स्टेटमेंट्स कंपाइलर को बताते हैं कि हम कौन सा डाटा और किस प्रकार का डाटा इस्तेमाल करेंगे।
2. इनपुट/आउटपुट स्टेटमेंट्स
(A) फ़ॉर्मैटेड आउटपुट — printf()
टेक्स्ट, वेरिएबल और परिणाम को एक निश्चित तरीके से दिखाने के लिए।
&
(address-of operator) is used before variable names in scanf() except for
strings.
Common
Format Specifiers for Input
Data Type
Format Specifier
Example Input
int
%d
25
float
%f
3.14
char
%c
A
string
%s
Hello
Examples:
int age;
scanf("%d", &age);// Reads an integer
float price;
scanf("%f", &price);// Reads a float
char grade;
scanf("%c", &grade);// Reads a character
char name[20];
scanf("%s", name);// Reads a string (no & for strings)
Unformatted Input & Output
Statements in C
In C programming, unformatted I/O statements are used for simple character or string reading and writing
without using format specifiers like %d, %f, etc.
They work directly
with characters or strings and are also provided by the stdio.h
library.
1.
Unformatted Output Statements
(a) putchar()
Outputs a single character to the screen.
Syntax:
putchar(character);
Example:
putchar('A');// Displays: A
(b) puts()
Outputs a string followed by a newline (\n).
Syntax:
puts(string_variable);
Example:
char name[] = "Rahul";
puts(name);// Displays: Rahul (then goes to next line)
2.
Unformatted Input Statements
(a) getchar()
Reads a single character from the keyboard.
Syntax:
variable = getchar();
Example:
char ch;
ch = getchar(); // User enters 'A'
(b) gets()(Not recommended in modern C because it is
unsafe)
Reads a string (including spaces) until Enter is
pressed.
Syntax:
gets(string_variable);
Example:
char name[20];
gets(name);// User enters: Rahul Kumar
gets()
can cause memory overflow, so in modern C, fgets() is preferred.
3. Expression Statements
An expression is anything that produces a value — like
a calculation, assignment, or function call.
Example:
1. Simple Expression Statements
Contain only one operation.
Examples:
x = 5;//
Simple assignment
count++;//
Increment
y--;//
Decrement
2. Complex Expression Statements
Contain multiple operations in the same
statement.
Examples:
result = (a + b) * c;// Arithmetic + assignment
x = y + z - w / 2;// Multiple operators
sum = a++ + --b;// Increment + addition
4. Control Statements
Types of
Control Statements
A. Conditional (Decision-making) Statements
Used to make
decisions based on a condition (true or false).