[go: up one dir, main page]

0% found this document useful (0 votes)
112 views5 pages

C Language Complete Guide PDF

The document provides a comprehensive guide to the C programming language, covering its features, applications, and basic structure. It includes detailed explanations of C tokens, data types, variables, control statements, functions, arrays, strings, pointers, structures, file handling, and dynamic memory allocation. This guide serves as an essential resource for students learning C programming.

Uploaded by

santoshpuvvada13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views5 pages

C Language Complete Guide PDF

The document provides a comprehensive guide to the C programming language, covering its features, applications, and basic structure. It includes detailed explanations of C tokens, data types, variables, control statements, functions, arrays, strings, pointers, structures, file handling, and dynamic memory allocation. This guide serves as an essential resource for students learning C programming.

Uploaded by

santoshpuvvada13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

C Language Complete Guide for Students

1. Introduction to C Language

C is a general-purpose, procedural programming language developed by Dennis Ritchie in 1972 at Bell Labs. It is widely
used for system software, operating systems, embedded systems, and application development.
Features of C:

• Simple and efficient


• Procedural language
• Fast execution
• Low-level memory access
• Modularity through functions
• Portability

Applications of C:

• Operating systems (e.g., UNIX)


• Embedded systems
• Compiler design
• Network drivers
• Game development
• Database systems

2. Basic Structure of a C Program

#include <stdio.h>

int main() {
printf("Hello, World!\n"); return 0;

3. C Tokens

• Keywords: int, float, if, else, return, etc. •


Identifiers: Names of variables, functions •
Constants: Fixed values • Strings: Text
enclosed in double quotes • Operators: +, -, *, /,
%, etc. • Special Symbols: {}, (), [], ;, #

1
4. Data Types in C

• int •
float •
double •
char •
void

Example:

int age = 20; float salary =


35000.50; char grade = 'A';

5. Variables and Constants

const float PI = 3.14; // constant //


int number = 10; variable

6. Input and Output

scanf("%d", &number);
printf("Number is: %d", number);

7. Operators

• Arithmetic: +, -, *, /, % •
Relational: >, <, >=, <=, ==, !=
• Logical: &&, ||, ! • Assignment:
=, +=, -= •
Increment/Decrement: ++, --

2
8. Control Statements
If-Else Statement

if (x > 0) {
printf("Positive");
} else {
printf("Non-positive");
}

Switch Statement

switch(choice) {
case 1: printf("One"); break; case 2:
printf("Two"); break; default:
printf("Invalid");
}

Loops

• for
• while
• do...while

Example:

for (int i = 0; i < 5; i++) {


printf("%d ", i);
}

9. Functions in C

int add(int a, int b) {


return a + b;
}

int main() {
printf("Sum = %d", add(5, 3));
return 0;
}

3
10. Arrays

int arr[5] = {1, 2, 3, 4, 5}; for (int i = 0; i


< 5; i++) {
printf("%d ", arr[i]);
}

11. Strings

char str[] = "Hello";


printf("%s", str);

12. Pointers

int a = 10; int *p = &a;


printf("Value: %d",
*p);

13. Structures and Unions


Structure Example

struct Student {
int id; char
name[50];
};

Union Example

union Data {
int i; float
f;
};

4
14. File Handling

FILE *fp; fp = fopen("file.txt", "w");


fprintf(fp, "Hello"); fclose(fp);

15. Dynamic Memory Allocation

int *ptr = (int*) malloc(5 * sizeof(int)); free(ptr);

You might also like