Standard Library Functions

Understanding C Standard Library Functions and Headers

Introduction to Standard Library (स्टैंडर्ड लाइब्रेरी का परिचय)

C standard library pre-defined functions का collection है जो common programming tasks को perform करने में help करता है। ये functions different header files में organized होते हैं।

The C standard library is a collection of pre-defined functions that help perform common programming tasks. These functions are organized in different header files.

Key Points (मुख्य बिंदु):

  • Standard library functions ready-made solutions provide करते हैं
  • Standard library functions provide ready-made solutions
  • Functions को use करने के लिए appropriate header file include करना important है
  • Including appropriate header file is important to use functions
  • Standard library functions efficient और well-tested होते हैं
  • Standard library functions are efficient and well-tested
stdio.h
stdlib.h
string.h
math.h

stdio.h Functions (stdio.h फंक्शन्स)

Input/Output functions और उनका use:

Input/Output functions and their usage:

#include 

// Input functions
int num;
scanf("%d", &num);

// Output functions
printf("Number: %d\n", num);

// File operations
FILE *fp = fopen("file.txt", "w");
fprintf(fp, "Hello World\n");
fclose(fp);
Function (फंक्शन) Description (विवरण)
printf() Formatted output print करता है
printf() Prints formatted output
scanf() Formatted input read करता है
scanf() Reads formatted input

stdlib.h Functions (stdlib.h फंक्शन्स)

General purpose functions और उनका use:

General purpose functions and their usage:

#include 

// Memory allocation
int *arr = (int*)malloc(10 * sizeof(int));
free(arr);

// Type conversion
char str[] = "123";
int num = atoi(str);

// Random numbers
srand(time(NULL));
int random = rand() % 100;

Common Functions (कॉमन फंक्शन्स):

  • malloc() और free() memory management के लिए
  • malloc() and free() for memory management
  • atoi(), atof() string से number conversion के लिए
  • atoi(), atof() for string to number conversion
  • rand() और srand() random numbers generate करने के लिए
  • rand() and srand() for generating random numbers

string.h Functions (string.h फंक्शन्स)

String manipulation functions और उनका use:

String manipulation functions and their usage:

#include 

// String operations
char str1[20] = "Hello";
char str2[20] = "World";

strcat(str1, str2);    // Concatenation
strcpy(str2, str1);    // Copy
int len = strlen(str1); // Length
int cmp = strcmp(str1, str2); // Comparison

math.h Functions (math.h फंक्शन्स)

Mathematical functions और उनका use:

Mathematical functions and their usage:

#include 

// Mathematical operations
double x = 2.0;
double y = sqrt(x);    // Square root
double z = pow(x, 3);  // Power
double a = sin(x);     // Sine
double b = log(x);     // Logarithm

Best Practices (सर्वोत्तम प्रथाएं)

Standard library functions के best practices:

Best practices for standard library functions:

  • Header Files: Required header files को include करें
  • Header Files: Include required header files
  • Error Checking: Function return values को check करें
  • Error Checking: Check function return values
  • Memory Management: malloc() के साथ free() का use करें
  • Memory Management: Use free() with malloc()
  • Type Safety: Correct data types का use करें
  • Type Safety: Use correct data types