C Programming Questions and Answers | C Language Questions and Answers

Q1. What is program? What are the different steps of program development?

Ans: program is a set of instructions that a computer follows in order to perform a particular task. Programs are created using specific programming languages such as C, C++, Java, Python etc.

A program is a set of instructions that process input, manipulate data, and output a result. For example, Microsoft Word is a word processing program that allows users to create and write documents.

Program development is the process of creating programsA program development process consists of various steps that are followed to develop a computer program. These steps are followed in a sequence in order to develop a successful and beneficial computer program.  Following is a brief description of the program development process.


Analyze the problem:

In this step, a programmer must figure out the problem, and then decide how to resolve the problem - choose a program.


Design the program:

The programmer designs an algorithm to help visual possible alternatives in a program also.

A flow chart is important to use during this step of the program development. This is a visual diagram of the flow containing the program. This step will help you break down the problem.


Code the program:

This is using the language of programming to write the lines of code. The code is called the listing or the source code.


Debug the program:

Debugging is a process of detecting, locating and correcting the bugs in a program. The bugs are important to find because this is known as errors in a program.


Formalize the solution:

One must run the program to make sure there are no syntax and logic errors. Syntax are grammatical errors and logic errors are incorrect results.


Document and maintain the program:

This step is the final step of gathering everything together. When the program is finalized, its documentation is prepared.

 

Q2. What is algorithm? What are its various characteristics?

Ans: An algorithm is simply a set of steps used to complete a specific task. It is a finite set of instructions carried out in a specific order to perform a particular task.


Characteristics of an Algorithm:

An algorithm should have the following characteristics:


Input

An algorithm requires some input values. There should be zero or more inputs supplied externally to the algorithm.


Output

There should be at least one output produced.


Definiteness or Unambiguity:

Algorithm should be clear and unambiguous. Each of its steps should be clear and simple in all aspects and must lead to only one meaning.


Finiteness: 

The algorithm must be finite. Here, finiteness means that the algorithm should contain a limited number of instructions. Algorithms must terminate after a finite number of steps.


Effectiveness:

An algorithm should be effective as each instruction in an algorithm affects the overall process.. Every instruction must be basic and must be feasible.

 

Q3. What is preprocessor directive? Why it is required?

Ans: The commands of the preprocessor are known as preprocessor directives. Preprocessor directive begin with a hash symbol (#).It is placed before the main().The # is followed by an identifier that is the directive name. For example, #define is the directive that defines a macro.


Some preprocessor directives are: #include, #define, #undef etc.

Preprocessor directives, such as #define and #ifdef, are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to take specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text.

 

Q4. What is syntax error and semantic error? Write at least two differences between them.

Ans:

Syntax Error:

When we write a program, errors can arise. If the errors concern the syntax, we call them syntax errors. Syntax errors occur when a programmer makes mistakes in typing the code's syntax. In other words, syntax errors occur when we write a statement that does not follow the set of rules defined for the syntax of C language. As a result, the program can’t run, and error message will show.

The compiler will generally catch syntax errors and generate warnings or errors, so programmer can easily identify fix the problem.  The most commonly occurring syntax errors in C language are missing semi-colon (;), missing parenthesis ({}).


Semantic error:

When we write a program, errors can arise. If the errors concern the semantics, we call them semantic errors. A semantic error occurs when the code is syntactically correct but does not do what the programmer intended.

The most commonly occurring semantic errors are: use of un-initialized variables, type compatibility, and array index out of bounds.



Q5. Explain different types of errors in C.

Ans: 

Q6. What is the function of linker and loader? Explain.

Ans: 


Q7. What are delimiters? Explain any two of them with their functions.

Ans: A delimiter is a unique character or series of characters that indicates the beginning or end of a specific statement, string or function body set.

Delimiters are used in programming languages to specify code set characters or data strings, serve as data and code boundaries and facilitate the interpretation of code and the segmentation of various implemented data sets and functions.

Programming languages use delimiters in different coding scenarios to determine specific type and instruction boundaries. Because delimiters - such as commas and full stops - define different condition types, the delimiter concept is very similar to the English language.

Delimiter examples include:

  • Round brackets or parentheses: ( )
  • Curly brackets: { }
  • Escape sequence or comments: /*
  • Double quotes for defining string literals: " "

 

Q8. Draw the basic structure of a C program.

Ans: Every C program is basically a group of different section that is used for different purpose. The structure gives us a basic idea of the order of the sections in a program. A well-defined structured layout makes program more readable, easy to modify, consistent format and gives better clarity and the concept of a program. Whenever we write a program in ‘C’ language, we can divide that program into six different sections. These sections are as follows:

  • Documentation section
  • Linkage section
  • User definition section
  • Global declaration section
  • Main() function section
  • Subprogram section




Q9. Briefly explain the general steps of writing a C program.

Ans: Every C program is basically a group of different section that is used for different purpose. The structure gives us a basic idea of the order of the sections in a program. A well-defined structured layout makes program more readable, easy to modify, consistent format and gives better clarity and the concept of a program. Whenever we write a program in ‘C’ language, we can divide that program into six different sections. These sections are as follows:

  • Documentation section
  • Linkage section
  • User definition section
  • Global declaration section
  • Main() function section
  • Subprogram section


Q10. State the series of steps for executing a program written in C.

Ans: The compilation and execution process of C program follows multiple steps. A brief explanation of each step is given below:


Step 1: Creating Source Code

When we write a program in ‘C’, that program is called source code. Every c program source file is saved with .c extension. To create source code, we use any text editor. The instructions written in the source code must follow the C programming language rules.


Step 2: Compiling the program

The compilers job is to translate the instructions in the source file into instructions called executable code that the operating system can understand and execute.  The source code passes through a number of intermediate stages before it turns into executable code.  The source code is sent to the preprocessors first.

Preprocessor: Preprocessor processes the source code before compilation. It performs some task like removing comments, include header files, expand the macros etc. The preprocessor generates the expanded source code. Then the expanded source code is passed to the compiler.

Compiler: Compiler will compile the program. It first checks the program errors, if errors are found it returns a list of errors.  If the compiler reports no error, then it converts source code into the object code and stores it as a file with extension .obj. Then the object code is given to the Linker.

Linker:  Linker is another important part of the compilation process. It takes the object code and links it with required library files. After linking, the linker generates executable code with extension .EXE which is ready to execute. The executable code is sent to loader


Step 3: Executing / Running the program

Loader: Whenever we give the command to execute a particular program, the loader comes into work. Loader loads the executable file into the main/primary memory and then it is executed. After execution, output is sent to the monitor screen of the computer.


Q11. What is compiler?


Q12. What is header file in C? List any two header files.


Q13. What are library functions? Give example.


Q14. What is the significance of stdio.h?


Q15. What is the difference between “stdio.h” and “string.h”? Explain.


Q16. What is the purpose of scanf() function?


Q17. What is the difference between scanf() and gets().


Q18. What is keyword in C?


Q19. What is the use of %d in C?


Q20. What is the use of \t in C?


Q21. Mention how to write a comment in C?


Q22. What is source code?

Ans: Source code is the set of instructions a programmer writes using computer programming languages. This code is later translated into machine language by a compiler. Source code is the source of a computer program.


Post a Comment

1 Comments

if you have any doubts plz let me know...