Monday, April 23, 2012

C - Objective Questions

C - Objective Questions

Introduction to Programming in C
1. Write the Basic structure of C program?
      The basic structure of a C program is
v  Documentation Section
v  Linking Section
v  Definition Section
v  Global Declaration Section
2. What is variable?
            A variable is a data name that is used to store a data value. It represents a location in the memory.
3. What is a Constant?
            Constants are fixed values that do not change during the execution of the program.
4. Give example of Trigraph characters? 
     Trigraph               Equivalent
       ========     ==========
      ??=                    #
      ??/                      \
      ??'                      ^
      ??(                      [
      ??)                      ]
5. Give example of Backslash Character constants?
1.      \a -> Bell
2.      \b-> Backspace
3.      \n->new line
4.      \r->carriage return
6. List the types of C tokens?
o   Keywords
o   Identifiers
o   Constants
o   Strings
o   Special symbols
o   Strings 
o   Operators
7. What is a Keyword?
These are reserved words, called keywords that have standard, fixed, predefined meanings in C. These meanings cannot be changed. All the keywords are written in lower case.
8. What is a data type?
It specifies the type of the variable stored in t he memory that is storage representation of the variable.
9. List the various type of data types
1.      Primary or fundamental data type
2.      User-defined data type
3.      Derived data type
10. What is User defined Data type? Give an example
     C supports a feature known as “type definition” that allows users to define an identifier that would represent an existing data type.
            Typedef identifier;
11. What are the types of User defined Data type?
ü  Typedef
ü  Enum
12. What are the different types of Constants?
                                                        ii.      Numeric Constants
                                                      iii.      Character Constants.
13. What is an operator?
            An operator is a symbol which is used to perform certain mathematical and logical manipulations.
14. List out the different types of operators.
·         Arithmetic Operators
·         Relational Operators
·         Logical Operators
·         Assignment Operators
·         Increment and Decrement Operators
·         Conditional Operators
·         Bitwise Operators
·         Special Operators


15. What is Conditional operator?
       A conditional operator also called ternary operator is denoted as ?: The conditional     operator consists of 2 symbols the question mark (?) and the colon (:).
            For example
           
a=10; b=15; x=(a>b)?a:b
16. What is sizeof operator?
            It is a complie time operator it returns the number of bytes the operand occupies.
17. Give an example of Comma operator?
       For example, the statement
           value = ( x = 10, y = 5, x + y); 
       first assigns the value 10 to x, then assigns 5 to y and finally assigns 15 to value.
18. What is Automatic Type Conversion?
             If the operands are of different types, the lower type is automatically converted to the higher type before the operation proceeds this is called automatic type conversion. The result is of the higher type. The following are the rules that are applied while evaluating expressions.
1.      All short and char are automatically converted to int.
2.      All float are automatically converted to double.
19. What is Preprocessor?
      The preprocessor is a program that processes the source code before it passes through the compiler. Preprocessor directives are placed in the source program before the main line.    They all begin with the symbol #  in column one and do not require a semicolon at the end.
20. What is the use of printf() and scanf()?
      printf:
Ø  This refers to an output data that has been printed in a particular format
Ø  This function used to write/print formatted data to the screen
Syntax:
      printf(“control string”, &var1, &var2,….,&varn);
scanf:
The control string specifies the field format in which the data is to be entered and the var1,var2,….varN specify the address of locations where the data is stored. The control string and variables are separated by commas.
Ex:    scanf(“%d”,&number);