0% found this document useful (0 votes)
11 views2 pages

C Language Syntax and Basics Guide

The document provides an overview of the C programming language, including its history, basic syntax, and structure of a C program. It covers essential topics such as data types, variables, operators, control flow statements, functions, arrays, strings, pointers, dynamic memory allocation, structures, and file handling. An example program is also included to illustrate basic input and output operations.

Uploaded by

koushikkota307
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)
11 views2 pages

C Language Syntax and Basics Guide

The document provides an overview of the C programming language, including its history, basic syntax, and structure of a C program. It covers essential topics such as data types, variables, operators, control flow statements, functions, arrays, strings, pointers, dynamic memory allocation, structures, and file handling. An example program is also included to illustrate basic input and output operations.

Uploaded by

koushikkota307
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

C Language Syntax & Notes

1. Introduction to C:
- Developed by Dennis Ritchie in 1972 at Bell Labs.
- General-purpose, procedural language.
- Foundation for many languages like C++, Java, Python.
- Still widely used in embedded systems, OS kernels, and compilers.

2. Basic Syntax:
Every C program has this general form:
#include <stdio.h> // Header file int main() { // Your code here return 0; }
3. Structure of a C Program:
1. Preprocessor Directives (#include, #define)
2. Global Declarations (variables, constants)
3. main() Function (entry point)
4. Other Functions

4. Data Types:
- int → integers (e.g., int age = 20;)
- float → decimal numbers (e.g., float price = 5.99;)
- char → single characters (e.g., char grade = 'A';)
- double → large decimal precision
- void → no return value

5. Variables & Constants:


- Variables store data and have types.
- Constants are fixed values (use 'const' keyword).

6. Operators:
- Arithmetic: + - * / %
- Relational: == != < > <= >=
- Logical: && || !
- Assignment: = += -= *= /=
- Increment/Decrement: ++ --

7. Control Flow Statements:


- if, if-else, nested if
- switch-case
- for, while, do-while loops
- break, continue, goto

8. Functions:
Syntax:
return_type function_name(parameters) { // code return value; } Functions make code reusable and
organized.

9. Arrays:
- 1D Array: int arr[5];
- 2D Array: int matrix[3][3];

10. Strings:
- Stored as char arrays.
- Use <string.h> functions like strlen(), strcpy(), strcmp().

11. Pointers:
- Variables that store memory addresses.
Example:
int a = 10; int *p = &a; - Pointer arithmetic (*, &).

12. Dynamic Memory Allocation:


- malloc(), calloc(), realloc(), free()

13. Structures:
struct Student { char name[20]; int age; }; - Groups different data types together.

14. File Handling:


- fopen(), fclose(), fprintf(), fscanf()
- Modes: r, w, a, rb, wb

15. Example Program:


#include <stdio.h> int main() { int num; printf("Enter a number: "); scanf("%d", #); printf("You
entered: %d", num); return 0; }

You might also like