CH-10
Introduction to C Language
Programming language when used allows us to write an instruction that has only one meaning.
Computers however do not understand the language that we speak neither does it understand the programming language. It only understands 0 and 1.
The problem of computers not understanding our language is solved by using software programs called translators. This translator is known as compiler.
A good program should possess following characteristics :
1. A program must end after finite number of steps.
2. The instructions of program must be precisely defined, i.e. it should not have multiple
meaning.
3. All the instructions must be effective, i.e. they should be carried out exactly.
4. A program may take zero or more inputs.
5. A program may produce one or more outputs.
Structure of C Program
C program is a set of blocks called functions. A function is made up of one or more statements used for performing a predefined task.
It is always a good practice to use comments within the functions as it improves the readability and understanding of the program. C language has 2 type of comment single line :- // and multiline comment as /* and */
C provides inbuilt or library functions. Some examples are pow(), sqrt() etc. These functions have a predefined purpose like pow() is used for calculating value of x raised to given power.
A scope of C variable is decided by using opening and closing curly braces { }.
The characters here can be divided into four categories.
1. Letter
2.Digits
3. White spaces
4. Special Characters.
Keyword :- To be specific ANSI C standard supports 32 predefined words. These predefined words in C language are known as keyword.
auto ,double ,int ,struct
break ,else ,long ,switch
case ,enum ,register ,typedef union
char ,extern ,return ,const
float ,short ,unsigned ,continue
for ,signed ,void ,default ,goto
sizeof ,volatile ,do ,static ,while
Identifier :- A word that a user can construct by making use of C character set is known as identifier. It consists of set of letters, digits and some special characters
Variable :- AC program generally accepts input, this input comes in a form of data. To store and manipulate a data we use memory space.
These rules have been mentioned below :
1. Variable name cannot be same as keyword.
2. Variable name consists of letter, digit and under score. No other special character is allowed.
3. The first character of variable name must be a letter or under score.
4. The maximum length of variable name as per ANSI standards is 31 characters.
5. The variable names are case sensitive hence num, nuM, nUM, nUm and Num are considered as different variables.
Constant :- The entities of C that do not change its value throughout the execution of program are known as constant.
1) Which of the following is an extension of C program file ?
(a) c
(b) h
(c) s
(d) t
(2) Which of the following number refers to number of C character categories?
(a) 0
(b) 2
(c) 4
(d) 8
(3) Which of the following C character categories does the symbol = belong ?
(a) Letter
(b) Blank Space
(c) Special Character
(d) Digit
(4) Which of the following is a valid keyword of C ?
(a) ofsize
(b) sizeof
(c) forsize
(d) sizefor
(5) Which of the following is an invalid variable name in C?
(a) Register
(b) Register
(c) registre
(d) register
(6) Which of the following is an invalid integer constant in C ?
(a) OxG
(b) OxA
(c) OxB
(d) 0xD
(7) Which of the following is valid real constant in C?
(a) -2.0.5e5
(b) -20.5e5.5
(c) -20.5e5
(d) -20.5e.5
(8) Which of the following is valid single character constant in C ?
(a) 'a'
(b) 'la'
(c)"a"
(d) Both a and b
(9) The preprocessor directive #define is used to define which of the following in C ?
(a) String constant
(b) Symbolic constants
(c) Integer constant
(d) Single character constant
(10) Which of the following function key is used to directly execute a program ?
(a) F7
(b) F9
(c) F5
(d) F8