Easy and Fundamentals of C Programming: An In-Depth Look at Variables, Data Types, Operators, and More
C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.
Here are some basic concepts of C programming:
Variables: A variable is a storage location in memory that holds a value. It has a name, a data type, and a value.
Data types: C supports various data types such as int, float, char, etc.
Operators: C supports various operators such as arithmetic, relational, logical, and bitwise operators.
Control statements: C supports various control statements such as if-else, for, while, and do-while loops.
Functions: C supports the use of functions, which are self-contained blocks of code that can be called by other parts of the program.
Arrays: C supports arrays, which are collections of variables of the same data type.
Pointers: C supports the use of pointers, which are variables that store memory addresses.
Strings: C supports strings, which are arrays of characters terminated by a null character.
File handling: C supports file handling, which allows you to read from or write to a file.
Preprocessor: C has a preprocessor which is a program that processes the source code before the compiler translates it.
Before lean You just Note this below
| Category | Type of Constant | Description | Example |
|---|---|---|---|
| Numeric Constants | Integer Constant | A positive or negative whole number. | 12, -7 |
| Real Constant | A fractional number, can be represented in different forms: Floating Point Constant and Real Constant in Exponential Form | 3.14, 6.8e8 | |
| Character Constants | Single Character Constant | A single character, such as an alphabet, digit, or special symbol enclosed within single quotes. | 'a', 'Z', '3', '$' |
| String Character Constant | A sequence of characters enclosed in double quotes. | "Hello World!", "19282" | |
| Special Characters | \' | Single quote | ''' |
\" | Double quote | '"' | |
\\ | Backslash | '\' | |
\n | Newline | '\n' | |
\t | Horizontal tab | '\t' | |
\r | Carriage return | '\r' | |
\a | Alert or bell | '\a' | |
\b | Backspace | '\b' | |
\f | Form feed | '\f' | |
\v | Vertical tab | '\v' |
Please note that some of these characters have different behavior on different systems, and please keep in mind that these are the standard backslash characters but it may vary based on the operating system or compiler you are using.
In C programming, type qualifiers are used to specify the properties of a variable. Here are some common basic types and their corresponding qualifiers, and their size in bytes:
| Type | Qualifier | Size (bytes) |
|---|---|---|
| char | signed/unsigned | 1 |
| short | signed/unsigned | 2 |
| int | signed/unsigned | 4 |
| long | signed/unsigned | 4 |
| long long | signed/unsigned | 8 |
| float | - | 4 |
| double | - | 8 |
| long double | - | 10 |
It's worth noting that the size of these types may vary depending on the compiler, operating system, and architecture. Also, some compilers support more types like _int8, _int16, _int32, _int64 which are also platform dependent.
Please keep in mind that these are the standard types and their size but it may vary based on the operating system or compiler you are using.
Table: Integer and Variable
| Category | Description | Example |
|---|---|---|
| Integer | Occupies memory within computer memory | signed integer, unsigned integer |
| Integer Storage | Memory used to store depends on machine configuration | 16-bit processor: 2 byte integer type can occupy, 32-bit processor: 4 byte of memory of integer value, 64-bit processor: 8 byte of memory of integer value |
| Type Modifier | C language allows alteration of integer storage using type modifier | short int, long int (greater) |
| Modifiers | Memory occupied by different data types | char (signed/unsigned), 1 byte, short (signed/unsigned), 2 bytes, int (signed/unsigned), 4 bytes, long (signed/unsigned), 4 bytes, long long (signed/unsigned), 8 bytes, float, 4 bytes, double, 8 bytes, long double, 10 bytes |
| Fractional Value | Fractional values cannot be stored in integer type, truncation of fractional value | Use float data type to store integer values |
| Variable Introduction | Named location in memory that holds specific data type | Example: Integer variable can only store integer values, cannot store other values such as float and character |
| Variable Declaration | Syntax: data_type variable_name | Example: int x, y, z (comma separated) |
| Variable Rules | Variable name must begin with a letter or underscore, case sensitive, can be constructed with digits and letters, cannot use special symbols other than underscore, keywords cannot be used, recommended to use 8 characters or less | |
| Variable Initialization | Syntax: data_type variable_name = value; | Example: int x = 50, y = 30 (x and y are of type integer) |
| Variable Scope | Local Variable: declared inside a function, Formal Parameter: variable can be a formal parameter, Global Variable: declared outside a function |
Comments
Post a Comment