Saturday, December 5, 2015

Std 7 - chapter 5 - ITKT (Computer) - Introduction to C Language - Cycle Test 3

5. Introduction to ‘C’ language
Que 1 Fill in the blanks
1.     Errors are mistakes in program, which     are traced by the compiler.
2.     Clrscr() is the function which clears the previous output.
3.     C programming was designed and written by Dennis Ritchie.
4.     C is a case sensitive language.
5.     Variable are used to store value or data of any type.
6.     getch() is kept as the last statement of the of the program so that after program  code gets executed and the output is printed on the screen.
7.     getch() holds the screen so that output can be seen.
8.     Output can be seen on the screen with the help of getch() function.
9.     C was developed at AT & T Bell Laboratories of USA in 1972.
10.               The C compiler translates  the C source program to machine language.
11.               The output of the C compiler is called object file.
12.               Object file are saved with .obj extension.
13.               The linker combines different object files to  produce the executable file.
14.               Keywords are the reserved words used in programming.
15.               Keywords  has the fixed meaning that can’t be changed by the user.
16.               There are 32 keywords available in C.
17.               Constants are values that can’t be changed during the execution of a program.
18.               Variable  are used to store value or data of any type.
19.               The value stored in a variable can change during the execution of a program.
20.               Variables are names given to locations in the  computer’s memory.

Que 2.Which rules must be follwed to construct variable names?
Ans.
 1) A variable name should consist only alphabets, digits and underscore, which can be short to reduce your typing effort.
2) First character of variable name must be an alphabet or underscore.
3) No commas, spaces, special symbols except underscore should be present in the variable name.
4) variable name should not exceed 31 characters.
5) Keywords can not be used as variable names.

Que 3. Identify the correct / incorrect variable names. Justify your answer if the variable name is incorrect.
1.     Sum_1 :– Valid
2.     Add5 :– Valid
3.     6overs :– Invalid
6overs is an invalid variable because the first character of a valid variable must be an alphabet or underscore. It can’t be digit.
4.     Result value :– Invalid
Result value is an invalid variable because no commas or spaces should be present in the variable name.
5.     Case :– Invalid
Case is a keyword of C language and keywords cannot be used as variable names.

Que 4. Answer the following questions.
a)                 What are key words?
Ø Keywords are the reserved words used in programming.
Ø Keyword has a fixed meaning and that cannot be changed by the user.
Ø There are 32 keywords available in C.
Ø For ex – auto, break, case, char, constant etc…
b)                Give any two features of C programming?
Ø C has a rich set of built-in functions.
Ø These help us in re-using readily available programs.
Ø C is a middle level language as it combines the capabilities of low level programming with features of high level language.
Ø It has a variety of ‘data types’ such as character, numeric and alphanumeric.
Ø C programs are highly portable since the program written in one computer can be run on another computer.
c)                 ‘C is a case sensitive language’ justify the statement.
‘C is a case sensitive language’ because commands written in uppercase and lowercase are not same.
For ex. Datatype int is not equal to INT or Int.
d)                What are datatypes explain with example.
Ø Datatypes in c are used to define a variable before its use.
Ø It specifies which type of data the variable can hold.
Ø C has the following built – in data types.
1)    int – integer data type can be used to store a whole number.
For ex - int a;
                         a = 5;
2)    char – character data type can be used when we require storing a single character.
For ex - char ch;
                     ch = ‘y’;
3)    float – float data type is used when we want to store decimal numbers.
For ex - float per;
                      Per = 55.67%
4)    double – double is also used t store decimal numbers but it has more precision and higher range than float.
For ex – double per
                     Per = 2556784.2568;
Que 5. What is the use of getch() function?
                        getch() is predefined function which accepts a character at the execution time. It holds the screen till the user presses a key.

Que 5 Write down the steps to learn the C language.
Ans. The steps to learn  C are:
            Step 1 Alphabets, Digits, Special symbols
            Step 2 Constant, Variable, Keywords
            Step 3 Instructions
            Step 4 Programs

Que 6 How to compile and execute a C program?
Ans.          The process of converting a C program into an executable program is done in 2 stages:
1)                Compiling 2) Linking
The C compiler translates the C source program to machine language or  object file which are saved with .obj extension and obj file also has information to aid the linker.

The linker combines different object files to  produce the executable file with .exe extension.

Que 7. Explain Data Type
Ans :
o   Data Types in C are used to define a variable before its use.
o   It specifies which type of data variable can store.
o   The type of data also declares how much space it will require in the computer’s memory.
o   General syntax:
Data type var1, var2, var3 ….varn;
      C has following  built in data types:
1.     Int – used to store a whole number. It can be positive or negative numbers like 1,-2 etc.
2.     Char – Character data type can be used when we require storing a single character. The character can be an alphabet, number, space or any special symbol.
3.     Float – Float is used when we want to store decimal numbers. For ex. 55.67
4.     Double – Double is also used to store decimal numbers, but it has more precision and higher range than float. For ex  255584.35

 Que 8. Explain Operators in C.
Ans.       An operator is a symbol which instructs the compiler to perform a specific mathematical or logical operation.
                           C provides the following types of built-in operators:
v Arithmetic Operators
The following table shows all the arithmetic operators supported by the C language. Assume variable A holds 10 and variable B holds 20, then −
Operator
Description
Example
+
Adds two operands.
A + B = 30
Subtracts second operand from the first.
A − B = 10
Multiplies both operands.
A B = 200
Divides numerator by de-numerator.
B ∕ A = 2
%
Modulus Operator and remainder of after an integer division.
B % A = 0
v Relational Operators
 The following table shows all the relational operators supported by C language. Assume variable A holds 10 and variable B holds 20 then −
Operator
Description
Example
==
Checks if the values of two operands are equal or not. If yes, then the condition becomes true.
(A == B) is not true.
!=
Checks if the values of two operands are equal or not. If values are not equal then the condition becomes true.
(A != B) is true.
> 
Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true.
(A > B) is not true.
< 
Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true.
(A < B) is true.
>=
Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true.
(A >= B) is not true.
<=
Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true.
(A <= B) is true.


v Logical operators
 Following table shows all the logical operators supported by C language. Assume variable A holds 1 and variable B holds 0, then −
Operator
Description
Example
&&
Called Logical AND operator. If both the operands are non-zero, then the condition becomes true.
(A && B) is false.
||
Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true.
(A || B) is true.
!
Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false.
!(A && B) is true.

v Assignment operators
            The following table lists the assignment operators supported by the C language
Operator
Description
Example
=
Simple assignment operator. Assigns values from right side operands to left side operand.
C = A + B will assign the value of A + B to C

v Increment/Decrement operator
Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs.
++
Increment operator increases the integer value by one.
A++ = 11
--
Decrement operator decreases the integer value by one.
A-- = 9

Que 9. Write down the steps to write a c program.
§  C program should be always written in the lower case.
§  All the statements inside the function should end with a semicolon (;).
§  main ()  is the first function.
§  All the variable should be declared before using.
§  Every opening brace or parenthesis should have a closing brace or parenthesis.

Que 10. Write a simple C program and explain it in detail.
1./* First C program */
2.#include <stdio.h>
3.#include <conio.h>
4.void main()
5.{
6.Clrscr () ; // this statement clears the output screen
7.printf(“Hello World! “);
8.getch();
9.}
1st line – A  comment in c begins with /* and ends with */. Comments are non executable statements, used to add some description  or explanatory notes in a program for documentation./* …… */ is used to  for multilane comments while // is used for single line comment.

2nd line – Preprocessor directive: stdio.h is a standard input/output header file. The #include is called a compiler directive and tells the compiler to include a standard c library called stdio.h. Inbuilt c libraries are always inside angle brackets < >.

3rd line – This is again a preprocessor directive statement. We have included console input/output header file since we are using its predefined functions clrscr () and getch (). 

4th line – All the programming in C are made up of functions, and the one called main always runs first.
The name of this function is main, and since the function does not return any value, the return data type of this function is void.

5th line – Immediately after the function starts, code inside the function should  be written inside the curly braces { }. This line contains the opening curly brace of the main function.

6th line – clrscr()  is a predefined function which clears the previous output from the output window. This  function should be always kept at the starting of the code. If kept after the code, it will result in blank output since it will clear the output before letting us see it.

7th line – printf () function is used to print the character, string, float, integer, octal and hexadecimal values onto the output screen. The string or character written inside the double quotes will print as it is in the output screen. We can also use escape sequence characters in printf() function.
8th line – getch () is predefined function which accepts a character at the execution time. It holds the screen till the user pressed a key. It is kept as the last statement of program so that after the program code gets executed and the output is printed on the output screen, getch () function can hold the screen so that the output can be seen.

9th line – closing brace of main () function.

Que 11. Write down the steps to  execute a C program.
 Step 1. Type the program and save the file with .c extension.
Step 2.  Press Alt + F9 to compile the program. It will produce an object file.
Step 3. Press Ctrl + f9 to run the program. It will produce an executable file which can be run anytime.

Que 12. What is escape sequence? Explain in detail.
Ans. An escape sequence is two or more characters that often begin with an escape character (backslash-\). They are used to represent new line character, single quotation mark, or certain other special characters.

An escape sequence is regarded as a single character and is therefore valid as a character constant.( text in Bold font can be asked in give reason)

Following are some of the escape sequence characters used in C.
\a
\b
\f
\n
Newline (Line Feed); see notes below
\r
\t
\v

Que 13.Explain errors of C programs in detail.
Ans. Errors are mistakes in program, which are traced by the compiler while compilation. A program can only execute when all the errors are corrected.
 Types of errors:
1)                Logical errors – occur when the result we get is not correct because of the incorrect code logic.
2)                Syntax : occur when the grammar of the C language is not used properly.

For ex
1.     Typing Printf or print instead of  printf.
2.     Forgetting a semicolon (;) at the end of an executable C statement.
3.     Mismatch of parenthesis.

Que 14.Write a C program to add two numbers.
               #include<stdio.h>
               #include<conio.h>
               void main()
               {
                              int a, b, c;
                               clrscr();
                              a = 5;
                               b  = 2;
                              c = a + b;
                              printf ("Sum is = %d\n",c);
                               getch();
               }

Que 15. Explain Format Specifiers.
Ans. Format Specifiers are % sing followed by a letter which actually prints the value of the variable. Following are the list of format specifiers used in C to print the value of variables of different types.
%c
Character format Specifiers
%d
Signed Integer format Specifiers
%f
Floating point format Specifiers
%lf
Floating point format Specifiers
%s
String format Specifiers
%u
Unsigned Integer format Specifiers
%n
Prints nothing
%%
Prints % character






Note :- 

1. Cycle Test - 3 - Computer Syllabus - Chapter 4 & 5
2.Chapter 4 material is already uploaded on 24th Nov. 2015.
3.For better exam preparation students are suggested  to refer textbook and work book along with this material.
 

No comments:

Post a Comment