C LANGUAGE
🌟 C Language – Inventory & Versions
This page covers the history, versions, syntax, data types, variables, constants, and operators in C with examples.
1. Inventory (History & Origin)
| Year | Event |
|---|---|
| 1969–1972 | Developed by Dennis Ritchie at Bell Labs as a system programming language for UNIX. |
| 1978 | K&R C (first edition of The C Programming Language book published). |
| 1989 | ANSI C (C89) standard approved by ANSI. |
| 1990 | ISO C (C90) standardized internationally. |
| 1999 | C99 update introduced inline functions, variable-length arrays, // comments, and more. |
| 2011 | C11 introduced multi-threading support, Unicode handling, bounds-checking functions. |
| 2018 | C18 (minor revision of C11) — bug fixes and clarifications. |
2. Why Use C?
- Foundation of programming – base for languages like C++, Java, C#.
- System-level programming – OS, compilers, embedded systems.
- Portable – runs on almost any hardware.
- Performance – faster execution with low-level memory access.
3. Advantages of C
- Portable – works on different machines.
- Structured – modular programming support.
- Rich library – many built-in functions.
- Memory control – direct pointer manipulation.
- Fast execution – compiled directly to machine code.
4. Versions Summary
| Version | Year | Main Features |
|---|---|---|
| K&R C | 1978 | Original syntax & features. |
| ANSI C (C89) | 1989 | Standardized syntax, function prototypes, new keywords. |
| ISO C (C90) | 1990 | International standard with fixes. |
| C99 | 1999 | Inline functions, variable-length arrays, long long int, // comments. |
| C11 | 2011 | Multi-threading, Unicode, _Static_assert. |
| C18 | 2018 | Minor bug fixes and clarifications. |
📌 Basic Syntax in C
Syntax is the rule of writing C programs. If you break rules, you get errors.
#include <stdio.h> // Header file
int main() { // main function
printf("Hello, World!");
return 0;
}
int main() { // main function
printf("Hello, World!");
return 0;
}
Output:
Hello, World!
Hello, World!
- Every statement ends with
; main()is the starting point{ }group statements#includeadds header files
📌 Output in C
Output is the result displayed after running the program.
#include <stdio.h>
int main() {
printf("I am learning C");
return 0;
}
int main() {
printf("I am learning C");
return 0;
}
Output:
I am learning C
I am learning C
📌 Comments in C
Comments are ignored by compiler, used for explaining code.
Types:- Single-line:
// This is a comment - Multi-line:
/* This is multi-line */
#include <stdio.h>
int main() {
// Printing a message
printf("Backbenchers learn fast!");
/* This is
multi-line comment */
return 0;
}
int main() {
// Printing a message
printf("Backbenchers learn fast!");
/* This is
multi-line comment */
return 0;
}
Output:
Backbenchers learn fast!
Backbenchers learn fast!
📌 Data Types in C
Data types tell what kind of data a variable can store and memory size.
| Type | Size |
|---|---|
| char | 1 byte |
| int | 4 bytes |
| float | 4 bytes |
| double | 8 bytes |
| long long int | 8 bytes |
#include <stdio.h>
int main() {
int age = 20;
char grade = 'A';
float pi = 3.14;
double bigPi = 3.14159265;
printf("Age: %d\\n", age);
printf("Grade: %c\\n", grade);
printf("PI: %.2f\\n", pi);
printf("PI (double): %.8lf", bigPi);
return 0;
}
int main() {
int age = 20;
char grade = 'A';
float pi = 3.14;
double bigPi = 3.14159265;
printf("Age: %d\\n", age);
printf("Grade: %c\\n", grade);
printf("PI: %.2f\\n", pi);
printf("PI (double): %.8lf", bigPi);
return 0;
}
Output:
Age: 20
Grade: A
PI: 3.14
PI (double): 3.14159265
Age: 20
Grade: A
PI: 3.14
PI (double): 3.14159265
📌 Keywords in C
Keywords are reserved words that cannot be used as identifiers.
Example:
int number = 5; → here int is a keyword.Some keywords:
auto, break, case, char, const, continue, default, do, else, enum, extern, float, for, goto, if, int, long, return, short
📌 Variables in C
A variable is a named memory location to store data.
Rules:- Must start with letter or underscore
- Case-sensitive
- No spaces, no keywords
- Should be meaningful
#include <stdio.h>
int main() {
int age = 20;
float price = 99.50;
char grade = 'A';
printf("Age: %d\\n", age);
printf("Price: %.2f\\n", price);
printf("Grade: %c", grade);
return 0;
}
int main() {
int age = 20;
float price = 99.50;
char grade = 'A';
printf("Age: %d\\n", age);
printf("Price: %.2f\\n", price);
printf("Grade: %c", grade);
return 0;
}
Output:
Age: 20
Price: 99.50
Grade: A
Age: 20
Price: 99.50
Grade: A
📌 Constants in C
Constants are fixed values that cannot be changed during execution.
- Integer constants:
10, -45, 0 - Floating-point:
3.14, -0.001 - Character:
'A', 'z' - String:
"Hello"
#define PI 3.1416
const int age = 18;
const int age = 18;
📌 Operators in C
Operators perform operations on variables and values.
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, *=, /=
- Increment/Decrement: ++, --
- Bitwise: &, |, ^, ~, <<, >>
- Ternary: (condition) ? true : false
C language,we are learn in easy way to understand and also explanation with examples.
ReplyDelete