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

3) Character Constant: A symbol enclosed within a pair of single quotes(„) is called a character constant. Each character is associated with a unique value called an ASCII (American Standard Code for Information Interchange) code.
For ex: '9', 'a', '\n'
ASCII code of A = 65, a= 97, 0=48, etc 

4) String Constant: A sequence of characters enclosed within a pair of double quotes(“) is called a string constant. The string always ends with NULL (denoted by \0) character.
 For ex: "9", "a", "sri", "\n", “”

5) Escape Sequence Characters: An escape sequence character begins with a backslash and is followed by one character. 

A backslash (\) along with some character give special meaning and purpose for that character.

The complete set of escape sequences are: 
\b Backspace
\f Form feed
\n Newline
\r Return
\t Horizontal tab
\v Vertical tab
\\ Backslash
\' Single quotation mark
\" Double quotation mark
\? Question mark
\0 Null character

Question : What is datatype? List and explain different datatypes with examples. 

Datatype is an entity that defines set of values and set of operations that can be applied on those values.

Datatypes are broadly categorized as TWO types:

1) Primitive Data Types: Fundamental data types or Basic data types are primitive data types. 
Examples: int, char, float, double, void 

2) Non-Primitive Data Types: The derived or user-defined data types are called as nonprimitive data types. 
Examples: struct, union, pointers, etc

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz