2.Data Structure with Programming in C
Programming Concepts in C Language
C is a high level language. It is general as well as specific purpose language. It was developed at Bell laboratory, USA (now AT and 1 in 1972, by Dennis Ritchie and Brian Kernighan.
To learn C language we must first know what alphabets, numbers and special symbols are used in C, then how to use them, contents, variables and keywords are constructed and finally, how are these combined to form an instruction.
Character Set
The characters that can be used to form words, numbers and expressions depend upon the computer on which the program runs.
The characters in C are grouped into the following categories
(i) Letters (ii) Digits
(iii) Special characters (iv) White spaces
C Tokens
The smallest individual units are known as C tokens. C has six types of tokens.
C tokens
Keywords Identifiers Constants Operators String Special symbols
C tokens classifications
Keywords
All keywords (i.e., reserved words) are basically the sequences of characters that have one or more fixed meanings. All C keywords must be written in lowercase letters. e.g., break, char, int, continue, default, do etc.
Identifiers
Names given to the program elements such as variables, arrays and functions. Identifiers are sequences of alphabets and digits e.g., main, amount, emp_id etc.
Constants
Fixed values that do not change during the execution of a C program
Constants
Numeric constants Character constants
Integer constants Real constants Single character String constants
constants
Constants classification used in C language
Backslash character constants are used in output functions. e.g., ‘\b’ used for backspace and ‘\n’ used for new line etc.
Operator
It is symbol that tells computer to perform certain mathematical or logical manipulations. e.g., Arithmetic operators (+, — ,* , /) etc.
String
- A string is nothing but an array of characters (printable ASCII characters).
- Special Symbols g., [,], {,} etc.
Key Points
- An integer and real constant must have at least over digit.
- No commas or blanks are allowed within an integer constant and real
Variable
A variable is used to store data value. A variable is a data name that may take different values at different times during execution.
Comparison between Valid Variables and Invalid Variables
S.No. | Valid Variables | Invalid Variables |
1. | Marks | 6 pk |
2. | Total _mark | Total marks |
3. | Area_of_Cube | Area–of–cube |
4. | Num[10 ] | Ram’s- Age |
Population_2006 | Gross-salary-2009 |
Data Types
Data Typos
Primary/Built-in Derived/User defined
Integer Character Floating Double Array String Structure Union
point
Data types classification
Key Points
- An operation between a real and real always yields a real result.
- An operation between an integer and real always yields a real result. In this, the integer is first promoted to a real and then the operation is performed.
Delimiters/Separators
These are used to separate constants, variables and statements e.g., comma, semicolon, apostrophes, double quotes and blank space etc.
Different Types of Modifier with their Range
S.No. | Types of Modifier | Size (bytes) | Range of Values |
1. | int | 2 | — 32768 to + 32767 |
2. | signed int | 2 | — 32768 to + 32767 |
3. | unsigned int | 2 | 0 to 65535 |
4. | short int | 2 | — 32768 to + 32767 |
5. | long int | 4 | — 2147483648 to 4 2197483647 |
6. | float | 4 | — (3.4 E + 48) to + (3.4 E + 98) |
7 | double | 8 | — (1.7 E + 308) to (1.7E + 308) |
8. | char | 1 | — 128 to 127 |
9. | unsigned char | 1 | 0 to 255 |
Flow Chart of Compiling and Running a C Program
Key Points
- Syntax errors (i.e., violation of grammar).
- Logical errors (i.e., errors occur during coding process).
- Run-time errors (i.e., errors occurs when we attempt to run the ambiguous instructions).