Section A — 1 Mark Questions
1. Who developed the C programming language? [1 Mark]
Answer: Dennis Ritchie developed the C programming language at AT&T Bell Laboratories.
2. In which year was the C language developed? [1 Mark]
Answer: The C language was developed in 1972.
3. Who developed C++ and in what year? [1 Mark]
Answer: Bjarne Stroustrup developed C++ in 1980.
4. What is the extension of a C source file? [1 Mark]
Answer: The extension of a C source file is .c.
5. What is the extension of a C++ source file? [1 Mark]
Answer: The extension of a C++ source file is typically .cpp.
6. Define a C/C++ token. [1 Mark]
Answer: A token is the smallest individual unit in a program meaningful to the compiler.
7. What are keywords? [1 Mark]
Answer: Keywords are pre-defined, reserved words in a language that have special meaning to the compiler.
8. What is an identifier? [1 Mark]
Answer: An identifier is a user-defined name given to program elements such as variables, functions, and arrays.
9. State any one rule for naming an identifier. [1 Mark]
Answer: An identifier must begin with a letter or an underscore.
10. What is a basic data type? [1 Mark]
Answer: Basic data types are fundamental data types built into the language, such as int, char, float, and double.
11. What is the purpose of the void data type? [1 Mark]
Answer: The void data type specifies an empty set of values and is typically used to indicate that a function returns no value.
12. What is a symbolic constant? [1 Mark]
Answer: A symbolic constant is a name that substitutes for a numerical, character, or string constant using the #define preprocessor directive or the const keyword.
13. Give the syntax of a symbolic constant using #define. [1 Mark]
Answer: #define identifier value
14. What is variable declaration? [1 Mark]
Answer: Variable declaration informs the compiler about the data type and name of a variable.
15. What is variable initialization? [1 Mark]
Answer: Variable initialization is the process of assigning an initial value to a variable at the time of its declaration.
16. What is an enumerated data type? [1 Mark]
Answer: An enumerated data type is a user-defined data type consisting of a set of named integer constants called enumerators.
17. Name any two derived data types. [1 Mark]
Answer: Arrays and pointers.
18. What is the basic structure component where program execution begins in C/C++? [1 Mark]
Answer: The main() function.
19. What is the character set? [1 Mark]
Answer: A character set is a valid set of alphabets, digits, and special symbols that a language can recognize.
20. What is the role of the C/C++ compiler? [1 Mark]
Answer: The compiler translates the source code written in C/C++ into machine-understandable object code.
Section B — 2/3 Mark Questions
1. Explain the importance of C and C++ in programming. [2 Marks]
Answer: C provides low-level access to memory, making it efficient for system programming like operating systems. C++ introduces object-oriented programming features such as classes and inheritance, enabling the development of large-scale, complex software applications.
2. Differentiate between keywords and identifiers. [3 Marks]
Answer:
- Definition: Keywords are reserved words with fixed meanings, whereas identifiers are user-defined names for program components.
- Modification: The meaning of keywords cannot be changed by the programmer, but identifiers are defined by the programmer.
- Example: int and float are keywords, while sum and total are identifiers.
3. Explain enumerated data types with an example. [3 Marks]
Answer:
- Definition: An enum assigns names to integer values, improving code readability.
- Syntax: enum direction {North, South, East, West};
- Explanation: By default, North is assigned 0, South is 1, and so on, unless explicitly initialized otherwise.
4. Distinguish between variable declaration and variable definition. [2 Marks]
Answer: Declaration introduces the name and type of a variable to the compiler without necessarily allocating storage. Definition allocates memory storage for that declared variable. In many cases, a declaration acts as a definition simultaneously, such as int x;
5. What are derived data types? Give examples. [2 Marks]
Answer: Derived data types are built by combining or referencing basic data types. Examples include arrays, which store multiple elements of the same type, and pointers, which store the memory addresses of other variables.
6. Describe the role of symbolic constants in programming. [2 Marks]
Answer: Symbolic constants allow programmers to assign a descriptive name to a fixed value. They enhance code readability and make maintenance easier because a value that appears multiple times only needs to be updated at its definition point.
7. Outline the basic structure of a C or C++ program. [3 Marks]
Answer:
- Documentation Section: Contains comments describing the program.
- Preprocessor Directives: Includes header files like #include <stdio.h> or #include <iostream>.
- Main Function: The main() function where execution starts, containing executable statements inside curly braces.
8. Explain the character set used in C and C++. [2 Marks]
Answer: The character set comprises all the valid characters recognized by the compiler. It includes uppercase and lowercase alphabets (A-Z, a-z), digits (0-9), special symbols (like +, -, *, =), and white spaces (spaces, tabs, newlines).
9. What are constants? Differentiate between integer and floating-point constants. [3 Marks]
Answer:
- Constants: Fixed values that do not change during the execution of a program.
- Integer Constants: Whole numbers without any fractional part, such as 45 or -100.
- Floating-point Constants: Numbers containing fractional parts or decimal points, such as 3.14 or -0.005.
10. Briefly describe the execution process of a C/C++ program. [3 Marks]
Answer:
- Writing Source Code: The program is written and saved with an appropriate file extension.
- Preprocessing: The preprocessor handles directives like #include and #define.
- Compilation and Linking: The compiler converts source code into object code, and the linker links library functions to produce an executable file.
Section C — 5 Mark Questions
1. Explain the history, evolution, and significance of the C and C++ programming languages. [5 Marks]
Answer:
Introduction
C and C++ are foundational programming languages that have shaped modern software development, bridging the gap between low-level hardware control and high-level software abstraction.
History and Evolution of C
C was developed by Dennis Ritchie at AT&T Bell Laboratories in 1972. It was derived from earlier languages like B and BCPL. C was originally designed for implementing the UNIX operating system, providing efficiency and portability across different hardware architectures.
Evolution of C++
C++ was developed by Bjarne Stroustrup at Bell Laboratories starting in 1980. Initially called 'C with Classes', it was created to add object-oriented programming features to the C language while retaining its high efficiency and low-level system access.
Significance
Both languages remain significant today. C is widely used in embedded systems, device drivers, and operating systems. C++ powers high-performance applications, game engines, and large-scale software systems where resource management and execution speed are critical.
2. Discuss C and C++ tokens in detail, explaining each category with appropriate examples. [5 Marks]
Answer:
Introduction
Tokens are the fundamental building blocks of any C or C++ program. The compiler breaks down source code into these individual elements during lexical analysis.
Categories of Tokens
- Keywords: Reserved words with predefined meanings. Example: int, return, while.
- Identifiers: User-given names for variables, functions, and arrays. Example: totalScore, count.
- Constants: Fixed values that cannot be altered during execution. Example: 100, 3.14.
- Operators: Symbols that specify operations to be performed on data. Example: +, -, ==, &&.
- Special Symbols: Characters with special grammatical meaning in the syntax. Example: braces {}, parentheses (), commas ,.
Conclusion
Understanding tokens is essential because every line of valid C or C++ code is composed of a precise combination of these five lexical elements.
3. Classify and explain the various data types available in C and C++. [5 Marks]
Answer:
Introduction
Data types specify the type of data a variable can store, the amount of memory it occupies, and the operations that can be performed on it.
Classification of Data Types
- Basic Data Types: Fundamental built-in types such as integer (int), character (char), floating-point (float), and double precision floating-point (double).
- Enumerated Data Types: User-defined data types consisting of named integer constants (enum), which improve program readability.
- Derived Data Types: More complex types constructed from basic data types. Examples include arrays, pointers, and references.
Example and Memory Significance
For instance, an int typically occupies 4 bytes of memory, storing whole numbers, while a char occupies 1 byte, storing character symbols. Using the correct data type ensures efficient memory utilization and prevents overflow or truncation errors.
4. Explain constants and variables in C/C++, focusing on declaration, assignment, and symbolic constants. [5 Marks]
Answer:
Introduction
Constants and variables are the primary storage entities used to handle data during program execution.
Variables
A variable is a named memory location used to store data whose value can change during execution. Variables must be declared before use by specifying their data type and identifier name, such as:
int age;
Values are assigned using the assignment operator (=), such as:
age = 25;
Constants and Symbolic Constants
Constants are fixed values that remain unchanged throughout program execution. Symbolic constants give meaningful names to these fixed values. They are defined either using the preprocessor directive #define or the const keyword:
const double PI = 3.14159;
Conclusion
Proper declaration of variables and utilization of symbolic constants ensure that programs are both flexible in handling data and safe from accidental modifications of fixed values.
5. Describe the complete structure, character set, and execution process of a C/C++ program. [5 Marks]
Answer:
Introduction
Writing and executing a C or C++ program requires an understanding of its underlying structure, the character set used to write code, and the compilation pipeline.
Character Set and Program Structure
The character set includes letters, digits, special symbols, and white spaces. The program structure typically consists of preprocessor directives, global declarations, and the main() function where execution begins.
Execution Process Steps
- Source Code Creation: The program is written using valid tokens and saved as a source file.
- Preprocessing: The preprocessor processes file inclusions (#include) and macro substitutions (#define).
- Compilation: The compiler translates the preprocessed code into assembly or machine object code.
- Linking: The linker combines the object code with necessary library functions to create an executable file.
- Execution: The operating system loads the executable into memory and runs it.
Conclusion
A thorough understanding of these phases allows developers to write syntactically correct programs and effectively troubleshoot compilation and linking errors.