Wednesday 10 July 2013

C BASIC QUESTIONS AND ANSWERS - K MANOHAR GOUD

9866550012
C BASIC QUESTIONS AND ANSWERS 

Why are all header files not declared in every C program?

- Declaring all header files in every program would lead to increase in the overall file size and load of the program. It is not a good programming. 
- The choice header files that you want to declare in the program depends on the commands/functions you want to use in the program. Each header file contains different commands and functions. So we use only the files relevant to our program.


What is a newline escape sequence?

- A newline escape sequence is represented by the \n character.
- It is used to insert a new line while displaying the output data.
- To add more spaces you can use more \n characters.

What are pre-processor directives?

- Pre-processor directives are placed at the beginning of a C program. They begin with # symbol.
- This is the place, where library files are specified depending on the functions to be used in the program.
- Pre-processor directives are also used for declaration of constants.

What are header files? What are their uses?

- Header files are also called as library files.
- They carry two important things: the definitions and prototypes of functions being used in a program.
- For example: stdio.h is a header file that contains definition and prototypes of commands like printf and scanf.

Why is a semicolon (;) put at the end of every program statement?

- It is done for parsing process and compilation of the code.
- A semicolon acts as a delimiter. This tells the compiler where each statement ends, and can proceed to divide the statement into smaller elements for checking the syntax.

Are comments included during the compilation stage and placed in the EXE file as well?

- No, comments encountered by the compiler are disregarded.
- Their only purpose is guidance and ease of programmer. They have no effect on the functionality of the program.

What is the purpose of main( ) function?

The function main() calls / invokes other functions within it. The execution of the program always starts with main() function.
The main() function is :
- The first function to start a program
- Returns int value to the environment which called the program
- It can be called recursively.
- It is a user defined function, except the name
- Like other functions, main(0 function can receive arguments. It has a) argument count and b) argument vector(string argument)      

Differentiate between #include<...> and #include "..."

- #include<...> means that the directories other than the current one will be searched for the header file.
- #include "..." means that the current directory will be searched for the header file before any other directories.

Give an example of escape sequence in c.

• Newline character is the example of escape sequence in c.
• It is represented by symbol \n and is placed at the of control string.
• It is composed of 2 characters but is translated by the compiler into single character.
• It instructs the computer to move to the next line before the information is printed.
• Example: printf(“welcome to c “\n”) ;

Which function is used to input the values during execution of a program?

• The function scanf is used to input the values during execution of a program.
• Scanf stands for scan function or scan formatting.
• Syntax: scanf(“%d”, &n);
• %d shows the data type of value entered and the value is stored in’ n’.
• It is used where a numeric value or character is to be read into simple variable.


No comments:

Post a Comment