Q1) Explain Algorithm With Example. A Set of Instructions, or A Recipe, For Solving A Problem or Performing A Task
Q1) Explain Algorithm With Example. A Set of Instructions, or A Recipe, For Solving A Problem or Performing A Task
In C programming, tokens are the smallest units in the source code that have a
meaningful purpose. These are the building blocks from which C programs are
constructed. There are six primary types of tokens in C:
1. Keywords
These are reserved words that have a specific meaning in C and cannot be used
for any other purpose (like variable names). Examples include:
int, float, return, if, else, while, for, switch, break, etc.
2. Identifiers
3. Constants
Constants are literal values used directly in the code. They can be numeric
(integer or floating-point), character constants, or string literals. Examples:
4. Operators
Operators are symbols that perform operations on variables or values. There are
several types of operators in C:
Arithmetic operators: +, -, *, /, %
Relational operators: ==, !=, >, <, >=, <=
Logical operators: &&, ||, !
Assignment operator: =
Bitwise operators: &, |, ^, <<, >>
Increment/Decrement operators: ++, --
Other operators: sizeof, , (comma), ->, [], etc.
5. Punctuation (Separators)
These tokens are used to separate other tokens and structure the code. They
include:
a character set refers to the collection of characters that can be used in the
source code. It defines the set of symbols, letters, digits, punctuation marks, and
other characters that are available for use in the language.
Types of Characters in C
1. Letter Characters:
o Uppercase: A to Z
o Lowercase: a to z
2. Digit Characters: 0 to 9
3. Punctuation Characters:
o Symbols like !, @, #, $, %, ^, &, *, (, ), ,, . etc.
4. Whitespace Characters:
o Space:
o Tab: \t
o Newline: \n
o Carriage Return: \r
o Form Feed: \f
5. Escape Sequences:
o Characters like \', \", \\, \n, \t are special sequences used to
represent characters that are hard to type directly.
Q7) What is identifier and what are rules to be followed for naming identifier.
No Reserved Keywords:
Case Sensitivity:
No Special Characters:
Length Limitations:
The extern storage class is used to declare a variable or function that is defined
in another file. It allows multiple files to share the same variable or function.
Essentially, it tells the compiler that the definition of the variable or function is
located elsewhere, usually in another translation unit (another source file).The
key idea is that an extern variable does not create a new variable; it simply
refers to one that has been declared elsewhere.
Literal Constants:
Symbolic Constants:
These are constants defined with names to make code more readable.
They can be created using:
o #define (preprocessor directive)
o const keyword
Variable Declaration
Variable declaration is the process of telling the compiler about the type and
name of the variable. When a variable is declared, you're essentially informing
the compiler that you intend to use a variable of a specific type, and it needs to
allocate space in memory for it
Variable Initialization
int age = 25; // Initialize the variable 'age' with the value 25
float price = 10.99; // Initialize the variable 'price' with the value 10.99
char letter = 'A';