C प्रोग्रामिंग लैंग्वेज का नोट्स (C Programming Notes in Hindi) - Study Friend

C प्रोग्रामिंग लैंग्वेज का नोट्स (C Programming Notes in Hindi)

C प्रोग्रामिंग पर विस्तृत हिंदी नोट्स: बेसिक से लेकर एडवांस टॉपिक्स, सिंटैक्स, फंक्शंस, एरे, पॉइंटर्स और प्रोजेक्ट्स सहित।

कंप्यूटर मानव इतिहास का सबसे रोचक अविष्कार है, इससे न सिर्फ गणना होती है बल्कि कई तरह के जटिल कार्य संपन्न होते हैं, जैसे कि फोटो एडिटिंग, मल्टीमीडिया प्लेयर, गेमिंग, वीडियो एडिटिंग, एजुकेशन इत्यादि।  लेकिन कंप्यूटर को इन चीजों की समझ नहीं है, कंप्यूटर सिर्फ दो ही चीज समझता है - 0 और 1 (true और false ), जिसे binary  कोड कहते है। Binary code और मानव भाषा के बीच सम्बन्ध बनाने के लिए प्रोग्रामिंग लैंग्वेज का इस्तेमाल होता है, जैसे कि C, C++, Java, Python इत्यादि।

आज के इस पोस्ट में हमलोग C प्रोग्रामिंग लैंग्वेज के बारे में सम्पूर्ण जानकारी प्राप्त करेंगे। यह  C  प्रोग्रामिंग लैंग्वेज का नोट्स (C Programming Notes in Hindi) आपको एग्जाम में मदद करेगा, साथ ही कंप्यूटर भाषा को समझने में मदद करेगा।

तो चलिए, C को गहराई से समझने का प्रयास करते हैं।

C  प्रोग्रामिंग लैंग्वेज का नोट्स (C Programming Notes in Hindi)

C प्रोग्रामिंग लैंग्वेज का नोट्स (C Programming Notes in Hindi)
C Programming Notes in Hindi

C भाषा का इतिहास और महत्व

  • C एक पावरफुल हाई - लेवल प्रोग्रामिंग भाषा है।
  • इसे 1972 में, अमेरिकी कंप्यूटर वैज्ञानिक डेनिस रिची (Dennis Ritchie) ने AT & T के बेल लैब्स में बनाया था।
  • C बनने की प्रेरणा थी Unix ऑपरेटिंग सिस्टम को लिखने के लिए एक पोर्टेबल भाषा, ताकि इसे विभिन्‍न मशीनी प्लेटफॉर्म्स पर काम में लाया जा सके।
  • C की लोकप्रियता: यह तेज, लचीलापन (flexible), और सिस्टम‑लेवल प्रोग्रामिंग में मदद  करती है। इसी कारण C कई आधुनिक प्रोग्रामिंग भाषाओं (C++, Java, C#, Objective‑C आदि) की जननी मानी जाती है।

C लैंग्वेज क्यों सीखें?

  1. प्रोग्रामिंग को सिस्टम लेवल पर समझने के लिए – डाटा स्ट्रक्चर, मेमोरी मैनिपुलेशन भी C में सीधे संभव हैं, जो हार्डवेयर के काफी करीब होता है।
  2. OS, Device ड्राइवर, Embedded सिस्टम के लिए – इन क्षेत्रों में C आज भी डोमिनेंट है।
  3. Code मोडिफ़िकेशन समझने के लिए – C के निर्माण और टूल्स का अध्ययन, डेवलपमेंट प्रक्रिया को स्पष्ट बनाता है।
  4. Highly Efficient कोड लिखने में मदद मिलती है।
  5. हाई परफॉरमेंस सिस्टम बनाने में C का बहुत बड़ा योगदान है।

C प्रोग्रामिंग की संरचना (Program Structure)

एक साधारण C प्रोग्राम का skeleton/syntax

#include <stdio.h>  // Header file inclusion

// Function prototypes (यदि कोई हो)
int sum(int, int);

int main() {
    // Variable declarations
    int a = 5, b = 10;
    int s;

    // Function call
    s = sum(a, b);

    printf("Sum = %d\n", s);  // Output
    return 0;                 // Return statement
}

// Function definition
int sum(int x, int y) {
    return x + y;
}

मुख्य घटक:

  • #include <...>: Header files, जैसे stdio.h, stdlib.h, string.h, आदि।
  • main() फंक्शन: C प्रोग्राम का एंट्री पॉइंट।
  • वैरिएबल का निर्धारण (Variable Declaration)
  • स्टेटमेंट, एक्सप्रेशन और ब्लॉक्स
  • फ़ंक्शन घोषणा और परिभाषा

Lexical Structure

Identifiers & Keywords

  • Identifiers: नाम जो आप स्वयं चुनते हैं (variables, functions)। जैसे sum, myVar आदि। नियम: शुरू में letter या underscore, बाद में letter, digit या underscore।
  • Keywords: रिज़र्व्ड शब्द, जिन्हें आप इस्तेमाल नहीं कर सकते जैसे int, float, return, for, while, break आदि — कुल मिलाकर 32 (C99 मानक में)।

Tokens

  • मुख्य टोकन प्रकार:

    1. Identifiers (नाम)
    2. Keywords (कुंजीशब्द)
    3. Constants (स्थिरांक)
    4. Strings Literals (स्ट्रिंग/अक्षर)
    5. Operators (चिन्ह)
    6. Punctuation (सेमी‑कोलन, कोमा, ब्रैकेट आदि)

Constants

  • Integer Constants: 123, 0xFF, 012
  • Floating Constants: 1.23, 5.0, 3e5
  • Character Constants: 'a', '%', '\n'
  • String Constants: "Hello, World"

Whitespace & Comments

  • Whitespace (space, tab, newline) टोकन को अलग करने में मदद करती है।
  • Comments:

    1. Single-line: // यह एक कमेंट है
    2. Multi-line: /* यह भी एक कमेंट है */

Data Types & Variables

बेसिक डाटा टाइप्स

डाटा टाइप वर्णन साइज़ (आम तौर पर)
void कोई वैल्यू नहीं 0 bytes
char अक्षर (1 byte) 1 byte
short int छोटा पूर्णांक 2 bytes आम
int पूर्णांक (medium) 2–4 bytes
long int लंबा पूर्णांक 4–8 bytes
float सिंगल‑प्रिसिजन real 4 bytes
double डबल‑प्रिसिजन real 8 bytes
long double उच्च‑परिसीधन real 10–16 bytes

वैरिएबल्स (Variables)

वेरिएबल में किसी डाटा को स्टोर किया है।
  • घोषणा के साथ प्रारंभ: int age = 18;
  • एक साथ कई वैरिएबल: float x, y, z;
  • स्थिरांक: const int MAX = 100;
  • Default Initialization (Local variables) नहीं होते, Global variables default से 0 पर होते हैं।

Type Modifiers

  • signed, unsigned, short, long
  • उदाहरण: unsigned int, long long int, signed char आदि।

Operators in C

A. Arithmetic Operators

  • +, -, *, /, %
  • %: मॉड्युलस (जौ) ऑपरेटर, divisor से remainder देता है।

B. Increment / Decrement

  • Pre: ++i, --i
  • Post: i++, i--
  • Prefix vs Postfix फर्क समझना ज़रूरी — कोई फर्क तब पड़ेगा जब वैल्यू को एक्सप्रेशन में उपयोग करें।

C. Relational Operators

  • ==, !=, >, <, >=, <=

D. Logical Operators

  • && (AND), || (OR), ! (NOT)

E. Bitwise Operators

  • &, |, ^, ~, <<, >>

F. Assignment Operators

  • =, +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^=

G. Conditional (Ternary) Operator

  • Syntax: condition ? expr_true : expr_false

H. Comma (,) Operator

  • Sequence operator: evaluate left operand then right, result returns right operand.

I. Sizeof Operator

  • sizeof(type) या sizeof(variable), returns memory size.

Type Conversion & Casting

  • Implicit Conversion (Type Promotion): Auto conversion, जैसे int + float → float.
  • Explicit Conversion: (float) a / b.

Control Structures

1. Conditional Statements

If

if (condition) {
    // code
}

If-Else

if (cond)
    stmt1;
else
    stmt2;

If-Else If-Else Ladder

if (cond1) {
    // ...
} else if (cond2) {
    // ...
} else {
    // ...
}

Nested If

2. Switch-Case

switch (ch) {
    case 'a':
        //...
        break;
    case 'b':
        //...
        break;
    default:
        //...
}
  • break ना होने पर fall‑through behavior।

3. Loops

A. while

while (condition) {
    //...
}

B. do-while

एक बार ज़रूर चलेगा

do {
    //...
} while (condition);

C. for loop

for (int i = 0; i < n; i++) {
    //...
}

D. Nested Loops

Loops के अंदर loops हो सकते हैं।

4. Jump Statements

  • break: बाहर निकलना switch/loop से
  • continue: मौजूदा iteration छोड़कर अगली iteration पर गया
  • goto label: सीधे labeled statement पर

    goto error;
    ...
    error:
      printf("Error occurred");

Functions (फ़ंक्शन)

Function Structure

return_type function_name(parameter_list) {
    // body
}
  • उदाहरण:

    int add(int a, int b) {
        return a + b;
    }
    

Types

  1. No parameters, no return: void fun()
  2. Parameters, no return: void fun(int a)
  3. No parameters, return: int fun()
  4. Both: float multiply(float x, float y)

Function Prototype

int factorial(int n);
  • उपयोग करने के पहले टाइप चेक करने में मदद करता है। 

Call by Value vs Call by Reference

  • Default C में है call by value
  • Pointer arguments का उपयोग करके reference तरीके से काम कर सकते हैं:

    void swap(int *x, int *y) {
        int temp = *x;
        *x = *y;
        *y = temp;
    }
    

Recursive Functions

  • अपने आप को call करती है; base case से निकलेगा।
  • उदाहरण: Factorial, Fibonacci

Arrays (एरे)

1D Array

int arr[5] = {1, 2, 3, 4, 5};
  • Initialization optional ={0}, default शुरू के zeros।
  • Accessing: arr[i]

2D Array (Matrix)

int mat[3][4];
  • Usage:

    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 4; j++)
            mat[i][j] = i + j;
    

Multidimensional Arrays

3D arrays आदि संभव हैं।

Array of Strings

char str[3][20] = {"Hello", "World", "C User"};

Pointers (पॉइंटर)

मूल बातें

  • पॉइंटर में किसी वैरिएबल का एड्रेसstore होता है

    int x = 10;
    int *p = &x;
    printf("%d", *p);  // 10
    

डिफाइन

int *p;     // integer pointer
char *pc;   // character pointer

Types

  • type *ptr

Pointer Operators

  • &: address operator
  • *: dereference operator

Pointer Arithmetic

  • जब pointer किसी array में होता है तो आप p+1, p-1, p++ आदि कर सकते हैं — यह element-wise jumps करते हैं।

Null Pointer

int *p = NULL;

Void Pointer

  • Generic pointer, सभी types से compatible, लेकिन dereferencing नहीं कर सकते जब तक cast न करें।

Pointer to Pointer

int x = 5;
int *p = &x;
int **pp = &p;

Pointers and Arrays

  • Array नाम अपने आप address है:

    int arr[5];
    int *p = arr;  // arr == &arr[0]
    

Function Pointers

  • Pointer storing memory address of function:

    int (*fptr)(int, int) = sum;

Dynamic Memory Management (डायनेमिक मेमोरी)

Standard Functions (stdlib.h)

  • malloc(size)
  • calloc(n, size)
  • realloc(ptr, newsize)
  • free(ptr)

उपयोग

int *arr = malloc(n * sizeof(int));
...
free(arr);

चेतावनी

  • Memory leak: free न करने से।
  • Dangling pointer: free के बाद pointer को null कर दें।

Input / Output (कंसोल)

stdio functions

  • printf, scanf
  • putchar, getchar
  • gets, puts (gets unsafe – avoid!)

Formatted I/O

  • %d, %f, %c, %s, %u, %ld, %lf, %x, आदि।

Example

int n;
printf("Enter N: ");
scanf("%d", &n);
printf("Value = %d", n);

File Handling (फ़ाइल हैंडलिंग)

File Operations

  • FILE *fopen(const char *name, const char *mode);

    • Modes: "r", "w", "a", "r+", "wb", "rb" etc.
  • fprintf, fscanf
  • fgets, fputs
  • fread, fwrite
  • fclose

Example

FILE *fp = fopen("data.txt", "w");
if (fp == NULL) {
    perror("Error opening file");
    return -1;
}
fprintf(fp, "Hello File\n");
fclose(fp);

Strings (स्ट्रिंग्स)

  • स्टोर होती हैं as character arrays ending in '\0'.
  • String Functions (string.h):

    • strlen, strcpy, strcat, strcmp, strchr, strstr, strncpy, memcmp आदि।
  • Example:

    char s1[20] = "Hello";
    char s2[20];
    strcpy(s2, s1);
    strcat(s2, " C");
    printf("%s length = %lu", s2, strlen(s2));

Structures (स्ट्रक्चर) & Unions

Structures

  • Custom datatype grouping multiple vars:

    struct Person {
        char name[50];
        int age;
        float salary;
    };
    
  • भ्रष्टाचार:

    struct Person p1 = {"John", 30, 5000.0};
    

Access

  • . for object, -> for pointer

    p1.age = 31;
    struct Person *pp = &p1;
    pp->salary = 5500;
    

Arrays of Structs, Nested Structs possible

Unions

  • Share memory among members:

    union Data {
      int i;
      float f;
      char str[20];
    };
    
  • उपयोग:

    • एक समय में केवल एक वैल्यू useful
    • Memory optimize

Bit Fields (Extensions to Structs)

  • Bank of bits within a struct:

    struct {
       unsigned int width : 3;
       unsigned int height : 3;
    } rect;

Preprocessor Directives

शामिल करना (#include)

#include <stdio.h>
#include "myheader.h"

मैक्रो (#define)

#define PI 3.14159
#define MAX(a,b) ((a) > (b) ? (a) : (b))

Conditional Compilation

#ifdef DEBUG
  printf("Debug mode\n");
#endif

दोस्तों कोई platform-specific code लिखने में काम आता है।

Undefine

#undef PI

#error & #pragma

  • #error: custom compile-time error।
  • #pragma: compiler-specific निर्देश।

C Standard Library

मुख्य हेडर फाइल्स और उनके उपयोग:

  • <stdio.h> – Input/output
  • <stdlib.h> – Memory allocation, process control, conversions
  • <string.h> – String handling
  • <math.h> – Mathematical functions (sin, cos, sqrt)
  • <ctype.h> – Character tests (isalpha, isdigit)
  • <time.h> – Date और time handling
  • <assert.h> – Debugging assertions
  • <limits.h>, <float.h> – Data माप (limits)

⚠️ Error Handling & Debugging

Run-time Errors

  • Divide by zero, segmentation fault, invalid memory access।

Compile-time Errors

  • Syntax errors, undeclared identifiers, type mismatch।

Debugging Tools

  • printf() चर्चित तरीका
  • Advanced: gdb, valgrind for memory issues।

Common Programming Techniques

Sorting Algorithms

Bubble sort, Selection sort, Insertion sort, Merge sort (recursively), Quick sort.

Searching

Linear search, Binary search (sorted arrays)

Data Structures

Implement using C:

  • लिंक्ड लिस्ट (single/double/ circular)
  • स्टैक (array/pointer)
  • क्यूज़
  • ट्री (binary)
  • ग्राफ़

फाइल‑आधारित डेटाबेस

C में छोटे‑छोटे database implement कर सकते हैं जैसे .txt या binary files।

Advanced Topics

Memory Layout

  • Program sections: Text, Data, BSS, Heap, Stack।

Segmentation Fault

  • गलत memory access पर segmentation fault आती है।

Valgrind Tool

  • Memory leak detect, invalid free, आदि दिखाता है।

Best Practices

  1. Comment & Document – हर फ़ंक्शन, block और logic का।
  2. Code Formatting – Indentation, spacing, naming convention (lower_case_with_underscores उचित होता है)।
  3. Modular Programming – छोटे फ़ाइलों में organize करें।
  4. Header Guards – Prevent double include (#ifndef, #define ... #endif)।
  5. Error Checking – Functions के return value काँफिगर करें।
  6. Avoid Magic Numbers – सिंबलिक constants का उपयोग करें।
  7. Memory Managementmalloc/free, null pointer checks, buffer overflow पहचानें।
  8. Boundary Testing – Array loops square brackets boundary.
  9. Type Safety – Casting और conversions सोच-समझकर करें।
  10. Secure Codinggets(), unchecked buffers avoid करें।

Example Programs (Code Snippets)

1. Factorial (Iterative + Recursive)

long factorial(int n) {
    long fact = 1;
    for (int i = 1; i <= n; i++) {
        fact *= i;
    }
    return fact;
}

long factorial_rec(int n) {
    if (n <= 1) return 1;
    return n * factorial_rec(n - 1);
}

2. Prime Checking

int isPrime(int n) {
    if (n <= 1) return 0;
    for (int i = 2; i <= n / 2; i++)
        if (n % i == 0) return 0;
    return 1;
}

3. Fibonacci Series

void fib(int n) {
    int a = 0, b = 1, c;
    for (int i = 1; i <= n; i++) {
        printf("%d ", a);
        c = a + b;
        a = b;
        b = c;
    }
}

4. Bubble Sort

void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < n - i - 1; j++)
            if (arr[j] > arr[j + 1]) {
                int tmp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = tmp;
            }
}

...

(नोट: पेपर पर ट्रेसिंग और boundary cases जरूर टेस्ट करें)

C प्रोजेक्ट आइडियाज़

  • स्टूडेंट मैनेजमेंट सिस्टम
  • बैंक अकाउंट मैनेजमेंट
  • Tic-Tac-Toe गेम
  • Matrix Calculator
  • Temperature Converter
  • चैट लॉग Analyzer
  • Image/Music File Sorter

Resources और आगे पढ़ने के लिए

  • K\&R (The C Programming Language) – Brian Kernighan & Dennis Ritchie
  • Let Us C – Yashavant Kanetkar (हिन्दी में उपलब्ध)
  • GeeksforGeeks, Tutorialspoint, Programiz
  • StackOverflow – Community support
  • GDB, Valgrind, gcc – Tools
  • GitHub – Open-source C प्रोजेक्ट्स

Appendix

  • ASCII मान, Escape sequences (\n, \t, etc.), टाइप लिमिट (INT_MAX, FLT_MIN), मैक्रो उदाहरण, header guards

निष्कर्ष

इस नोट्स में हमलोगों ने C  प्रोग्रामिंग लैंग्वेज के बेसिक कांसेप्ट को कवर किया, जिसमें syntax, semantics, memory, errors, best practices, और कुछ कोड उदाहरणों सहितशामिल था। इनका इस्तेमाल करके आप C में मजबूत पकड़ बना सकते हैं।

और अगर आप चाहें, तो मैं इससे PDF नोट्स, slides, या वीडियो ट्यूटोरियल्स भी बना सकता हूँ। एक कमेंट करके ज़रूर बताएं! आशा है कि यह पोस्ट आपको पसंद आया।

About the Author

Hey everyone, I'm Ganesh Kumar! I'm all about money matters, from stocks and mutual funds to making money online. I've been figuring them out for 4 years, and I love sharing what I learn through my journey! Sometimes I even throw in so…

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.