C - Introduction Question & Answer
Question :What are the alphabets or character set of C programming language?
Answer :
The characters that can be used to form words, numbers and expressions. The characters in C are grouped into the following categories
Letters: Lowercase letters a,b,...,z and uppercase letters A,B,...,Z
Digits: from 0 to 9
White spaces: Space, tab(\t), newline(\n), carriage return(\r), etc
Symbols:
Question : What are C-Tokens? List and define different C-Tokens with examples.
Answer :
A C-Token is a smallest element of a C program. One or more characters are grouped in sequence to form meaningful words. These meaningful words are called C-Tokens. The tokens are broadly classified as follows
Keywords: Keywords are tokens which are used for their intended purpose only. Each keyword has fixed meaning or predefined meaning and that cannot be changed by user. Hence, they are also called as reserved-words.
ex: if, for, while, int, float, break, char ..etc.
Identifiers: As the name indicates, identifier is used to identify various elements of program such as variables, constants, functions, arrays etc.
ex: sum, length, etc.
Constants: A constant is an identifier whose value remains fixed throughout the execution of the program. The constants cannot be modified in the program.
ex: 10, 10.5, 'a', "sri", etc.
Operators: An operator can be any symbol like + - * / that specifies what operation need to be performed on the data.
For ex: + indicates addition operation * indicates multiplication operation / indicates division operation, etc.
Special symbols: The symbols that are used to indicate array subscript, function call, block, etc.
ex: [], (), {}, etc.
Question : What are identifiers? What are the rules for naming a identifier? Give examples.
Answer :
Identifier is used to name various elements of program such as variables, constants,
functions, arrays, functions etc. An identifier is a word consisting of sequence of Letters,
Digits or _(underscore).
Rules to Name identifiers are
1. The variables must always begin with a letter or underscore as the first character.
2. The following letters can be any number of letters, digits or underscore.
3. Maximum length of any identifier is 31 characters for external names or 63 characters
for local names.
4. Identifiers are case sensitive. Ex. Rate and RaTe are two different identifiers.
5. The variable name should not be a keyword.
6. No special symbols are allowed except underscore.
Examples:
Valid identifiers:
Sum
roll_no
_name
sum_of_digits
avg_of_3_nums
Invalid Identifiers and reason for invalid:
$roll_no - Name doesn‟t begin with either letter or underscore
for - keyword is used as name
sum,1 - special symbol comma is not allowed
3_factorial - name begins with digit as first letter
Question : What are constants? List and explain different types of constants with examples
Answer:
A constant is an identifier whose value remains fixed throughout the execution of the
program. The constants cannot be modified in the program.
For example: 1, 3.14512, „z‟, “hello"
Different types of constants are:
1) Integer Constant: An integer is a whole number without any fraction part.
There are 3 types of integer constants:
i) Decimal constants (0 1 2 3 4 5 6 7 8 9) For ex: 0, -9, 22
ii) Octal constants (0 1 2 3 4 5 6 7) For ex: 021, 077, 033
iii) Hexadecimal constants (0 1 2 3 4 5 6 7 8 9 A B C D E F)
For ex: 0x7f, 0x2a, 0x521
2) Floating Point Constant: The floating point constant is a real number.
The floating point constants can be represented using 2 forms:
i) Fractional Form: A floating point number represented using fractional form has an integer part followed by a dot and a fractional part.
For ex: 0.5, -0.99
ii) Scientific Notation (Exponent Form): The floating point number represented using scientific notation has three parts namely: mantissa, E and exponent.
For ex: 9.86E3 imply 9.86 x 103