2nd Year Chapter 9 Elements Of C Question And Answer
Short And Simple Question And Answer
Q 1. What is an identifier?
Ans. In a program, the names used to represent variables, constants, types, functions, and labels are called identifiers. C compiler recognizes the first 31 characters of an identifier.
Q 2. What is a user-defined identifier?
Ans. User-defined identifiers are names assigned by the programmer to functions, data types, variables, etc., in a program. For example, “age” or “r_no” can be user-defined identifiers in a program.
Q 3. What is a standard identifier?
Ans. Standard identifiers are identifiers with predefined meanings in C language. These identifiers can be redefined, but it’s not recommended as redefining them can disrupt their original purpose. For example, “printf” and “scanf” are standard identifiers.
Q 4. What is a keyword?
Ans. Keywords are words in C language with predefined meanings and purposes. They cannot be used for any other purpose in C programs. All keywords are in lowercase and cannot be used as identifiers. C language has 32 keywords.
Q 5. What is a variable?
Ans. A variable is a named memory location used to store input data and results during the execution of a program. It can store different types of data and is essential for processing information.
Q 6. What is a constant?
Ans. A constant is a quantity with a fixed value that cannot be changed during program execution. Constants can be declared using the “const” keyword. For example, “const int x = 10;” defines a constant.
Q 7. What is variable declaration?
Ans. Variable declaration involves specifying the variable’s name and the data type it can contain. In C, variables must be declared before use. Failure to do so will result in a compiler error.
Q 8. What is variable initialization?
Ans. Variable initialization is the act of storing a value in a variable at the time of declaration. When a variable is declared, memory is allocated to it, and it may contain garbage values. Initialization sets the variable’s value before use.
Q 9. What is a typed language?
Ans. C is a strongly typed language, meaning that variables must be declared with a specific data type before use. This enforces strict typing, and the compiler checks for data type consistency at compile time.
Q 10. What are different types of constants?
Ans. There are two types of constants in C:
- Numeric constants
- Character constants
Q 11. What is meant by data type?
Ans. A data type defines a set of values and operations allowed on those values. It also specifies the memory required to store data. Data types play a crucial role in computer programming for processing various types of data.
Q 12. What is meant by standard data type?
Ans. Standard data types are predefined data types provided by the language, such as int, char, etc. These data types can be used in all C language programs.
Q 13. What is meant by user-defined data type?
Ans. User-defined data types are created by the programmer in addition to standard data types. These data types can only be used in the specific program in which they are defined.
Q 14. Which data types can be used to store integer data?
Ans. Data types for integers include:
- short int
- long int
- unsigned int
- unsigned long int
Q 15. Which data types can be used to store floating-point data?
Ans. Data types for real numbers include:
- long double
Q 16. What is cancellation error?
Ans. Cancellation error occurs when an arithmetic operation is performed between very large and very small floating-point numbers, leading to unexpected results. It can happen when adding a large number to a very small one, potentially canceling out the smaller value.
Q 17. What is meant by underflow?
Ans. Underflow occurs when a value is stored in a variable that falls below its minimum range, resulting in an error. For example, storing a number less than the minimum range of an “int” variable will trigger an underflow error.
Q 18. What is meant by overflow?
Ans. Overflow happens when a value is stored in a variable that exceeds its maximum range, leading to an error. For instance, storing a number greater than the maximum range of an “int” variable will trigger an overflow error.
Q 19. What is a character data type?
Ans. The character data type, “char,” is used to store single characters. A “char” type variable uses one byte in memory and stores the ASCII value of the character. It’s represented within single quotes, such as ‘?’, ‘a’, etc.
Q 20. How are characters stored?
Ans. Characters are stored as their ASCII values when assigned to a “char” type variable. The ASCII (American Standard Code for Information Interchange) value represents each character as a unique numeric code. For example, ‘A’ has an ASCII code of 65 and ‘B’ has a code of 66.
Q 21. What is an operator?
Ans. Operators are symbols used in computer programs to perform various operations on data. They can be used for tasks like addition, subtraction, comparison, and more.
Q 22. What are the different types of operators?
Ans. C language provides various types of operators, including:
- Arithmetic operators
- Relational operators
- Logical operators
- Increment and Decrement operators
- Assignment operators
Q 23. What is an arithmetic operator?
Ans. Arithmetic operators are used to perform mathematical operations on numeric data. These operations can be applied to numeric variables or constants, and they include addition, subtraction, multiplication, division, etc.
Q 24. What is an assignment operator?
Ans. The “=” symbol is called the assignment operator. It is used to store the result of an expression in a variable. For example, “x = 5” assigns the value 5 to the variable “x.”
Q 25. What is an assignment statement?
Ans. An assignment statement is a C language statement that uses the assignment operator “=” to assign a value or the result of an expression to a variable. It follows the format “variable = expression.”
Q 26. What is compound assignment?
Ans. Compound assignment involves assigning one value to multiple variables using the assignment operator more than once. For example, “A = B = 10;” assigns the value 10 to both variables A and B.
Q 27. What is a compound assignment operator?
Ans. Compound assignment operators are combinations of an assignment operator with an arithmetic operator. They are used to perform arithmetic operations and assign the result to a variable. Examples include “+=”, “-=”, “*=”, “/=”, and “%=”.
Q 28. What is the increment operator?
Ans. The double plus (“++”) sign represents the increment operator. It is a unary operator used to increase the current value of a variable by 1. It can be applied before or after the variable, such as “x++” or “++x.”
Q 29. What is the decrement operator?
Ans. The double minus (“–“) sign represents the decrement operator. It’s a unary operator used to decrease the current value of a variable by 1. Like the increment operator, it can be applied before or after the variable, such as “x–” or “–x.”
Q 30. What is a relational expression?
Ans. A relational expression is a combination of relational operators and operands, which can be constants or variables of the same type. It generates either a “true” or “false” result after evaluation.
Q 31. What are logical operators?
Ans. Logical operators include “AND” (&&), “OR” (||), and “NOT” (!), and they are used in compound expressions to make decisions based on the evaluation of relational expressions.
Q 32. What is a logical expression?
Ans. A logical expression combines relational expressions and logical operators to evaluate to a single numeric value. This value is used to make decisions in a program.
Q 33. What is the “AND” operator?
Ans. The “AND” operator (&&) yields a “true” result if both relational expressions on its sides evaluate to “true.” It’s used for combining conditions in a way where all conditions must be met for the overall expression to be true.
Q 34. What is the “OR” operator?
Ans. The “OR” operator (||) produces a “true” result if at least one of the relational expressions on its sides evaluates to “true.” It’s used to create conditions where any one of the conditions being true makes the overall expression true.
Q 35. What is the “NOT” operator?
Ans. The “NOT” operator (!) is used to negate the truth value of a relational expression. If an expression evaluates to “true,” applying the “NOT” operator will make it “false,” and vice versa.
Q 36. What is meant by operator precedence?
Ans. Operator precedence defines the order in which different types of operators in an expression are evaluated. It establishes the hierarchy of operators, ensuring that those with higher precedence are evaluated first.
Q 37. What is an expression?
Ans. An expression is a combination of operators and operands that is used to calculate the values of formulas. After evaluation, an expression yields a single value. The operands can be constants or variables.
Q 38. What are comments?
Ans. Comments are non-executable statements in a C language program, written between /* and */. The compiler ignores these lines. They are used for adding remarks, explanations, and improving program readability.
Q 39. What is a single-line comment?
Ans. A single-line comment is created in C using “//.” It is a non-executable statement that adds remarks or explanations and extends to only one line. These comments are used to improve code readability.
Q 40. What is a multi-line comment?
Ans. A multi-line comment is also written between /* and */, similar to single-line comments, but it can span multiple lines. These comments are useful for providing detailed explanations within a program.
Q 41. What is prefix increment?
Ans. Prefix increment (e.g., “++x”) is the use of the increment operator before a variable’s name. It increases the variable’s value by 1 and then uses the updated value.
Q 42. What is postfix increment?
Ans. Postfix increment (e.g., “x++”) is the application of the increment operator after a variable’s name. It uses the variable’s current value and then increments it by 1.
Q 43. What is prefix decrement?
Ans. Prefix decrement (e.g., “–x”) uses the decrement operator before the variable’s name. It decreases the variable’s value by 1 and then uses the updated value.