Tuesday, August 12, 2025

C भाषा में स्टेटमेंट्स

 

C भाषा में स्टेटमेंट्स (Statements) के प्रकार

C प्रोग्रामिंग में स्टेटमेंट्स को उनके काम के आधार पर अलग-अलग श्रेणियों में बाँटा जाता है।
नीचे इसका सरल विवरण दिया गया है:

स्टेटमेंट का प्रकार

उदाहरण

उद्देश्य

घोषणा (Declaration)

int x;

वेरिएबल्स के लिए मेमोरी सुरक्षित करना

इनपुट/आउटपुट (Input/Output)

printf()scanf()

इनपुट लेना और आउटपुट दिखाना

एक्सप्रेशन (Expression)

x = y + 5;

गणनाएँ/ऑपरेशन करना

शर्तीय (Conditional)

ifswitch

निर्णय लेना

लूप (Looping)

forwhile

कार्य को दोहराना

जंप (Jump)

breakcontinuereturngoto

प्रोग्राम के किसी अन्य भाग पर जाना


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; // घोषणा और प्रारंभिक मान const int MAX = 100; // कॉन्स्टेंट की घोषणा

💡 ये स्टेटमेंट्स कंपाइलर को बताते हैं कि हम कौन सा डाटा और किस प्रकार का डाटा इस्तेमाल करेंगे।


2. इनपुट/आउटपुट स्टेटमेंट्स

(A) फ़ॉर्मैटेड आउटपुट — printf()

  • टेक्स्ट, वेरिएबल और परिणाम को एक निश्चित तरीके से दिखाने के लिए।

  • stdio.h लाइब्रेरी द्वारा उपलब्ध।

सिंटैक्स:



printf("format string", variable1, variable2, ...);

आम फ़ॉर्मैट स्पेसिफ़ायर्स:

डाटा टाइपफ़ॉर्मैट स्पेसिफ़ायरआउटपुट उदाहरण
int%d या %i25
float%f3.140000
float(2 दशमलव)%.2f3.14
char%cA
string%sHello

उदाहरण:

printf("Age: %d\n", 15); printf("Price: %.2f\n", 45.678); printf("Grade: %c\n", 'A'); printf("Name: %s\n", "Rahul");

(B) फ़ॉर्मैटेड इनपुट — scanf()

  • कीबोर्ड से विशेष फ़ॉर्मैट में डाटा लेने के लिए।

  • stdio.h लाइब्रेरी द्वारा उपलब्ध।

  • वेरिएबल के नाम से पहले & लगाना ज़रूरी है (सिवाय स्ट्रिंग के)।

सिंटैक्स:



scanf("format string", &variable1, &variable2, ...);

आम फ़ॉर्मैट स्पेसिफ़ायर्स:

डाटा टाइपफ़ॉर्मैट स्पेसिफ़ायरइनपुट उदाहरण
int%d25
float%f3.14
char%cA
string%sHello

उदाहरण:

int age; scanf("%d", &age); float price; scanf("%f", &price); char grade; scanf("%c", &grade); char name[20]; scanf("%s", name);

3. अनफ़ॉर्मैटेड इनपुट/आउटपुट स्टेटमेंट्स

(A) अनफ़ॉर्मैटेड आउटपुट:

  1. putchar() — एक कैरेक्टर दिखाने के लिए।


putchar('A'); // आउटपुट: A
  1. puts() — एक स्ट्रिंग दिखाने के बाद नई लाइन पर जाने के लिए।


char name[] = "Rahul"; puts(name); // आउटपुट: Rahul

(B) अनफ़ॉर्मैटेड इनपुट:

  1. getchar() — एक कैरेक्टर पढ़ने के लिए।


char ch; ch = getchar();
  1. gets() — पूरी लाइन/स्ट्रिंग पढ़ने के लिए (आधुनिक C में सुरक्षित नहीं)।


char name[20]; gets(name);

4. एक्सप्रेशन स्टेटमेंट्स

(A) सरल (Simple) एक्सप्रेशन स्टेटमेंट

  • केवल एक ऑपरेशन होता है।


x = 5; count++; y--;

(B) जटिल (Complex) एक्सप्रेशन स्टेटमेंट

  • कई ऑपरेशन्स एक साथ होते हैं।


result = (a + b) * c; x = y + z - w / 2; sum = a++ + --b;

5. नियंत्रण (Control) स्टेटमेंट्स

(A) शर्तीय (Conditional) स्टेटमेंट्स


if (marks >= 33) printf("Pass"); if (marks >= 33) printf("Pass"); else printf("Fail"); switch (day) { case 1: printf("Monday"); break; case 2: printf("Tuesday"); break; default: printf("Invalid Day"); }

(B) लूप (Looping) स्टेटमेंट्स


for (i = 1; i <= 5; i++) printf("%d\n", i); i = 1; while (i <= 5) { printf("%d\n", i); i++; } i = 1; do { printf("%d\n", i); i++; } while (i <= 5);

(C) जंप (Jump) स्टेटमेंट्स


// break if (i == 5) break; // continue if (i == 3) continue; // goto goto label; // return return 0;


Control Statements in C

 

In C programming statements are usually grouped into categories based on what they do in a program.
Here’s a clear and simple breakdown.

Type of Statement

Examples

Purpose

Declaration

int x;

Reserve memory for variables

Input/Output

printf(), scanf()

Take input & display output

Expression

x = y + 5;

Perform operations

Conditional

if, switch

Make decisions

Looping

for, while

Repeat tasks

Jump

break, continue, return, goto

Used to jump to another part of the program

 


1. Declaration Statements

These are statements used to declare variables, constants, arrays, or functions before you use them in a program.
They tell the compiler:

The name of the data

The type of data (integer, float, char, etc.)

Sometimes the initial value

Syntax :- data_type variable_name;

Or        data_type variable_name = value;

Examples

int age;               // Declaring an integer variable

float price;           // Declaring a floating-point variable

char grade;            // Declaring a character variable

int rollNo = 101;      // Declaring and initializing

const int MAX = 100;   // Declaring a constant

 These tell the compiler about the type and name of data we will use.


2. Input/Output Statements

1. Formatted Output Statement — printf()

·        Used to display text, variables, and results in a controlled way.

·        Provided by the stdio.h library.

Syntax:

printf("format string", variable1, variable2, ...);

Common Format Specifiers for Output

Data Type

Format Specifier

Example Output

int

%d or %i

25

float

%f

3.140000

float (2 dp)

%.2f

3.14

char

%c

A

string

%s

Hello

Examples:

printf("Age: %d\n", 15);             // Integer output
printf("Price: %.2f\n", 45.678);     // Float with 2 decimal places
printf("Grade: %c\n", 'A');          // Character
printf("Name: %s\n", "Rahul");       // String

2. Formatted Input Statement — scanf()

·        Used to read data entered by the user from the keyboard in a specific format.

·        Provided by the stdio.h library.

Syntax:

scanf("format string", &variable1, &variable2, ...);

& (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).

  1. if statement

if (marks >= 33)

    printf("Pass");

  1. if...else statement

if (marks >= 33)

    printf("Pass");

else

    printf("Fail");

  1. switch statement

switch (day) {

    case 1: printf("Monday"); break;

    case 2: printf("Tuesday"); break;

    default: printf("Invalid Day");

}


B. Looping (Iteration) Statements

Used to repeat a block of code multiple times.

  1. for loop

for (i = 1; i <= 5; i++)

    printf("%d\n", i);

  1. while loop

i = 1;

while (i <= 5) {

    printf("%d\n", i);

    i++;

}

  1. do...while loop

i = 1;

do {

    printf("%d\n", i);

    i++;

} while (i <= 5);


C. Jump Statements

Used to jump to another part of the program.

  1. break

for (i = 1; i <= 10; i++) {

    if (i == 5) break; // Exit loop

    printf("%d\n", i);

}

  1. continue

for (i = 1; i <= 5; i++) {

    if (i == 3) continue; // Skip 3

    printf("%d\n", i);

}

  1. goto

goto label;

printf("This will be skipped");

label:

printf("Jumped here");

  1. return

return 0; // End function and return control

 

 


 

C भाषा में स्टेटमेंट्स

  C भाषा में स्टेटमेंट्स (Statements) के प्रकार C प्रोग्रामिंग में स्टेटमेंट्स को उनके काम के आधार पर अलग-अलग श्रेणियों में बाँटा जाता है। ...