0% found this document useful (0 votes)
14 views8 pages

C Programming Question Bank Guide

The document is a comprehensive question bank covering various aspects of C programming, including its basics, language components, data types, operators, input/output, decision making, loops, arrays, strings, functions, and storage classes. Each section contains multiple questions aimed at assessing knowledge and understanding of C programming concepts. It serves as a study guide for learners to prepare for exams or enhance their programming skills.

Uploaded by

sahilkhanks792
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

C Programming Question Bank Guide

The document is a comprehensive question bank covering various aspects of C programming, including its basics, language components, data types, operators, input/output, decision making, loops, arrays, strings, functions, and storage classes. Each section contains multiple questions aimed at assessing knowledge and understanding of C programming concepts. It serves as a study guide for learners to prepare for exams or enhance their programming skills.

Uploaded by

sahilkhanks792
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Programming: Expanded Question Bank

1. Basics of C
1 Who developed the C programming language and in which year?
2 Compare C with earlier languages like B and BCPL.
3 What are the main advantages of structured programming over unstructured programming?
4 Describe different file types in C programming with examples of when each is used.
5 What are the key features that make C a middle-level language?
6 Why is C considered both powerful and efficient?
2. C Language Components
1 What are tokens in C? List all types with examples.
2 Explain identifiers and naming rules in C.
3 Differentiate between variable declaration and definition.
4 What is a constant in C? How do you define symbolic and literal constants?
5 List the keywords in C. Can a keyword be used as a variable name? Why or why not?
6 Explain the use of escape sequences in character constants with examples.
3. Data Types and Operators
1 List all data types in C with their sizes and format specifiers.
2 What is the difference between signed and unsigned types?
3 Explain each arithmetic operator with a suitable code snippet.
4 What are logical operators and how are they used in decision making?
5 How do relational operators differ from logical operators?
6 Explain increment and decrement operators with pre and post examples.
7 What is the ternary operator and how is it useful?
8 Give examples of bitwise operations in C.
9 Explain special operators like sizeof and comma operator.
10 What is operator precedence and how does associativity affect evaluation?
11 Describe implicit and explicit type conversions with examples.
4. Input and Output
1 Differentiate between formatted and unformatted input/output functions.
2 How are scanf and printf functions used for different data types?
3 Explain the purpose and usage of format specifiers.
4 What are the common errors to avoid while using scanf?
5. Decision Making and Branching
1 Write a program using if-else to check if a number is positive, negative, or zero.
2 How does the else-if ladder simplify multiple conditions?
3 Give an example of a nested if-else structure and explain its flow.
4 Write a switch-case program for a simple calculator.
5 What happens if break is not used in a switch case?
6 What are the limitations of switch case statements?
7 How does a goto statement affect code readability and maintainability? Give examples.
6. Loops and Iteration
1 Explain the syntax and use-case of while, do-while, and for loops.
2 Give a comparative chart of entry-controlled and exit-controlled loops.
3 Write a program using nested loops to print a pattern.
4 What is the use of break and continue in loops? Provide examples.
5 Can loops be infinite? Give an example and explain how to stop them.
7. Arrays and Strings
1 What is an array and how is it different from individual variables?
2 How do you declare and initialize one-dimensional arrays?
3 Explain how two-dimensional arrays are stored and accessed in memory.
4 Give an idea about multidimensional arrays and their real-world applications.
5 How are strings stored in memory in C?
6 Write a program to reverse a string without using library functions.
7 Demonstrate the use of strlen, strcpy, strcat, and strcmp with examples.
8 Write a program to extract a substring from a given string.
9 Explain how to replace characters in a string using a loop.
10 How can two strings be concatenated without using strcat()?
8. Functions and Storage Classes
1 What are the benefits of using functions in C programs?
2 Differentiate between user-defined and library functions.
3 What is a function prototype and why is it important?
4 Explain the difference between actual and formal parameters.
5 Describe call by value and call by reference with code.
6 What are storage classes in C? Explain Auto, Extern, Static, and Register.
7 How do scope and lifetime of variables affect program behavior?
8 Write a recursive function to calculate factorial of a number.
9 When would you choose a recursive solution over an iterative one?
10 What is tail recursion? Give an example.
11 Compare function overloading and function overriding (if applicable to C).

Common questions

Powered by AI

Formatted input/output functions, such as printf and scanf, allow for specifying the format in which data is read or written, including types of data and spacing, by using format specifiers. This control makes them suitable for creating structured outputs or reading structured inputs reliably. Unformatted input/output functions, like getchar and putchar, read or write data as is, without attempt to interpret or structure it. They are typically used for simple data transfer or when maximum speed and minimum overhead are desired, such as reading raw bytes from a file .

Structured programming in C improves code readability and maintenance by dividing the program into small, manageable functions and modules, promoting the use of loops and conditionals instead of multiple goto statements. This enhances understanding and debugging as the control flow is clear and predictable. In contrast, unstructured programming can lead to spaghetti code, where the program's flow is difficult to follow due to excessive use of goto statements and lack of modular design .

The ternary operator simplifies decision-making structures by allowing a compact form of if-else that returns a value directly based on a condition. For example, in 'int result = (condition) ? value_if_true : value_if_false;', the operator checks 'condition', and if true, assigns 'value_if_true' to 'result'; otherwise, it assigns 'value_if_false'. This reduces the need for verbose if-else structures in simple assignments or expressions, making the code cleaner and easier to maintain .

C is classified as a middle-level language because it blends features of both high-level and low-level languages. It provides high-level constructs for structured programming and abstraction, similar to languages like Python or Java, while also offering low-level capabilities, such as direct memory access and manipulation like assembly language. This allows C to be both powerful and efficient, enabling system-level programming (e.g., for operating systems, drivers) and application development. By offering low-level operations, C can perform efficient memory management, crucial for resource-constrained environments .

Tokens in C are the smallest elements of a program meaningful to the compiler. They include keywords, identifiers, constants, strings, operators, and punctuation symbols. These components are essential for program compilation as they are the basic building blocks the compiler uses to interpret the source code. Without proper tokens, a compiler cannot analyze the program syntax or translate it into machine code .

Escape sequences in C enhance the functionality of character constants by allowing the inclusion of non-printable or special characters in strings, which cannot be directly represented. Examples include '\n' for a newline, '\t' for a tab, and '\\' for a backslash. They enable the control of output formatting and provide a way to include special characters, making strings more versatile and the visual output more organized .

Operator precedence determines the order in which different operators are evaluated in a complex expression, which is crucial for obtaining the correct result. Associativity defines the direction of evaluation when multiple operators of the same precedence level appear. For instance, in the expression 'a - b + c', precedence decides that subtraction and addition are evaluated from left to right due to their left associativity. Without clear rules for precedence and associativity, the intended logic of the expression could be lost, leading to incorrect calculations .

Implicit type conversion, or coercion, occurs automatically when an operation involves two different data types; C converts the smaller type to the larger type to enable the operation. For example, in 'int a = 5; float b = 6.2; float c = a + b;', integer 'a' is converted to float before the operation. Explicit type conversion involves the programmer manually specifying a conversion, using a cast operator, such as '(float)a' to explicitly convert 'a' to float for an operation. Implicit conversions can lead to unexpected results if data precision is lost, while explicit conversions provide control over how data types are handled, often preventing unintended behaviors .

Recursive functions, which call themselves with modified arguments, offer elegance and simplicity in solving problems like factorials or Fibonacci sequences, where the problem can be divided into similar sub-problems. This can lead to clearer and more straightforward code. However, recursion can be inefficient due to high memory usage as each call adds a layer to the call stack, risking stack overflow in deep recursions. Iterative solutions use loops, consuming less memory and often executing faster, making them a practical choice for performance-critical applications. Choosing between recursion and iteration involves evaluating the problem complexity, memory capacity, and system constraints .

You might also like