0% found this document useful (0 votes)
28 views20 pages

Unit I MCQ

Uploaded by

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

Unit I MCQ

Uploaded by

balavignesh4707
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Evolution of Programming & Languages

1. Which of the following is considered the first programming language?


o A) C
o B) Assembly
o C) Fortran
o D) Ada

Answer: B) Assembly

2. What does the term "machine language" refer to?


o A) High-level programming languages
o B) Binary code that a computer's CPU can execute directly
o C) Scripting languages
o D) Compiled languages

Answer: B) Binary code that a computer's CPU can execute directly

3. Which programming language was developed in the 1950s and is known for its use
in scientific and engineering applications?
o A) COBOL
o B) Lisp
o C) Fortran
o D) BASIC

Answer: C) Fortran

4. What does the acronym "COBOL" stand for?


o A) Common Business-Oriented Language
o B) Comprehensive Object-Based Language
o C) Common Object Business Language
o D) Computer Business Language

Answer: A) Common Business-Oriented Language

5. Which of the following languages introduced the concept of "garbage collection"?


o A) C
o B) Fortran
o C) Lisp
o D) Java

Answer: C) Lisp

6. In what year was the C programming language developed?


o A) 1969
o B) 1972
o C) 1983
o D) 1991

Answer: B) 1972

7. Which of the following is a significant feature of object-oriented programming


languages?
o A) Procedural Abstraction
o B) Data Abstraction
o C) Sequence Control
o D) Stack Memory Management

Answer: B) Data Abstraction

8. Which programming paradigm focuses on the use of functions and avoids changing-
state and mutable data?
o A) Procedural Programming
o B) Object-Oriented Programming
o C) Functional Programming
o D) Logic Programming

Answer: C) Functional Programming

9. Which programming language is widely known for its role in web development and
is often used on the client side?
o A) PHP
o B) Java
o C) JavaScript
o D) Ruby

Answer: C) JavaScript

10. What is the main purpose of a compiler in programming?


o A) To execute the program directly
o B) To translate source code into machine code
o C) To interpret scripts at runtime
o D) To debug code

Answer: B) To translate source code into machine code

Problem Solving Through Programming

1. What is the first step in the problem-solving process in programming?


o A) Writing code
o B) Testing the solution
o C) Defining the problem
o D) Analyzing results

Answer: C) Defining the problem

2. Which of the following is NOT a common strategy for problem-solving in


programming?
o A) Divide and conquer
o B) Trial and error
o C) Random guessing
o D) Pattern recognition

Answer: C) Random guessing

3. What does "pseudocode" help programmers to do?


o A) Execute the code
o B) Write actual code in a specific programming language
o C) Plan and design algorithms without worrying about syntax
o D) Optimize code performance

Answer: C) Plan and design algorithms without worrying about syntax

4. Which of the following best describes an algorithm?


o A) A set of instructions for solving a specific problem
o B) A programming language
o C) A bug in the code
o D) A type of data structure

Answer: A) A set of instructions for solving a specific problem

5. In programming, what does 'debugging' refer to?


o A) Writing new code
o B) Finding and fixing errors in the code
o C) Optimizing the performance of code
o D) Compiling the code

Answer: B) Finding and fixing errors in the code

6. What is a flowchart used for in problem-solving?


o A) To write the code directly
o B) To visualize the steps of an algorithm
o C) To test the code
o D) To manage software versions

Answer: B) To visualize the steps of an algorithm


7. Which data structure is most suitable for implementing a LIFO (Last In, First Out)
approach?
o A) Queue
o B) Stack
o C) Array
o D) Linked List

Answer: B) Stack

8. What is the purpose of a function in programming?


o A) To execute the entire program
o B) To group a set of related statements for reuse and organization
o C) To manage memory
o D) To define global variables

Answer: B) To group a set of related statements for reuse and organization

9. Which of the following programming constructs allows for making decisions in


code?
o A) Loop
o B) Function
o C) Conditional statement
o D) Variable

Answer: C) Conditional statement

10. What is the primary benefit of using algorithms in problem-solving?


o A) They can be directly executed by the computer
o B) They provide a systematic method for solving problems
o C) They eliminate the need for testing code
o D) They reduce the number of variables needed

Answer: B) They provide a systematic method for solving problems

Algorithm and Pseudocode

1. What is an algorithm?
o A) A programming language syntax
o B) A step-by-step procedure for solving a problem
o C) A type of software application
o D) A debugging tool

Answer: B) A step-by-step procedure for solving a problem

2. Which of the following is a characteristic of a good algorithm?


o A) It should be long and complex.
o B) It should have a clear stopping point.
o C) It should be written in a specific programming language.
o D) It should only work for one specific case.

Answer: B) It should have a clear stopping point.

3. What does pseudocode allow programmers to do?


o A) Write code that can be executed directly
o B) Plan an algorithm without adhering to a specific syntax
o C) Debug existing code
o D) Optimize performance of algorithms

Answer: B) Plan an algorithm without adhering to a specific syntax

4. In pseudocode, which of the following represents a decision-making process?


o A) IF-THEN-ELSE
o B) FOR loop
o C) PRINT statement
o D) FUNCTION definition

Answer: A) IF-THEN-ELSE

5. Which of the following is an example of a loop structure in pseudocode?


o A) IF condition THEN
o B) WHILE condition DO
o C) FUNCTION name(parameters)
o D) RETURN value

Answer: B) WHILE condition DO

6. What is the purpose of the 'RETURN' statement in an algorithm or pseudocode?


o A) To stop the execution of the program
o B) To provide the final result from a function
o C) To initialize variables
o D) To repeat a section of code

Answer: B) To provide the final result from a function

7. Which of the following best describes the term "flowchart"?


o A) A specific type of pseudocode
o B) A visual representation of an algorithm
o C) A type of programming language
o D) A debugging tool

Answer: B) A visual representation of an algorithm


8. What is the primary benefit of using pseudocode in algorithm design?
o A) It can be executed directly by a computer.
o B) It helps focus on the logic without worrying about syntax.
o C) It is the only way to write algorithms.
o D) It is faster than writing actual code.

Answer: B) It helps focus on the logic without worrying about syntax.

9. Which of the following represents a method of analyzing an algorithm's efficiency?


o A) Syntax checking
o B) Flowchart creation
o C) Big O notation
o D) Variable declaration

Answer: C) Big O notation

10. In pseudocode, how would you typically indicate the start of a loop?
o A) BEGIN LOOP
o B) FOR each item IN list DO
o C) LOOP START
o D) START LOOP

Answer: B) FOR each item IN list DO

Structure of C Program

1. Which of the following is the correct syntax for including a standard library in a C
program?
o A) #include <library.h>
o B) import library;
o C) include library.h;
o D) #include "library.h"

Answer: D) #include "library.h"

2. What is the purpose of the main() function in a C program?


o A) To define global variables
o B) To execute the program
o C) To include header files
o D) To declare functions

Answer: B) To execute the program

3. In C, which of the following is the correct way to declare a variable?


o A) int num;
o B) variable num: int;
o C) num int;
o D) int: num;

Answer: A) int num;

4. What symbol is used to indicate the end of a statement in C?


o A) .
o B) ;
o C) :
o D) ,

Answer: B) ;

5. Which of the following is the correct way to define a function in C?


o A) function void myFunction() { }
o B) void myFunction() { }
o C) myFunction() void { }
o D) void: myFunction() { }

Answer: B) void myFunction() { }

6. In C, what keyword is used to define a constant?


o A) const
o B) static
o C) define
o D) final

Answer: A) const

7. What is the purpose of the return statement in a function?


o A) To print output
o B) To end a program
o C) To return a value to the caller
o D) To declare a variable

Answer: C) To return a value to the caller

8. Which of the following correctly initializes an array in C?


o A) int arr[5] = {1, 2, 3, 4, 5};
o B) int arr(5) = {1, 2, 3, 4, 5};
o C) arr[5] int = {1, 2, 3, 4, 5};
o D) int arr[] = new int[5]{1, 2, 3, 4, 5};

Answer: A) int arr[5] = {1, 2, 3, 4, 5};

9. What does the #define directive do in a C program?


o A) It declares a variable
o B) It creates a macro or constant
o C) It includes a header file
o D) It defines a function

Answer: B) It creates a macro or constant

10. Which of the following statements is used for input in C?


o A) scan;
o B) read;
o C) scanf();
o D) input();

Answer: C) scanf();

I/O Functions, Variables, Constants, and Keywords in C

1. Which function is used to output formatted text to the console in C?


o A) print()
o B) output()
o C) printf()
o D) display()

Answer: C) printf()

2. What is the correct way to declare a constant integer in C?


o A) const int PI = 3.14;
o B) int const PI = 3.14;
o C) const PI = 3.14;
o D) #define PI 3.14

Answer: D) #define PI 3.14

3. Which of the following statements is used to read a string input in C?


o A) gets()
o B) read()
o C) input()
o D) scanf()

Answer: A) gets()

4. What is the output of the following code?

c
Copy code
int x = 5;
printf("%d", x++);

o A) 5
o B) 6
o C) 7
o D) Compilation error

Answer: A) 5

5. Which of the following is NOT a valid variable name in C?


o A) _temp
o B) temp1
o C) 1stTemp
o D) temp_name

Answer: C) 1stTemp

6. What keyword is used to indicate that a variable cannot change its value after
initialization?
o A) final
o B) static
o C) const
o D) immutable

Answer: C) const

7. Which function is used to read a single character from standard input?


o A) readchar()
o B) getch()
o C) getchar()
o D) inputchar()

Answer: C) getchar()

8. Which of the following is a valid declaration of a float variable?


o A) float num;
o B) float num = "3.14";
o C) float num : 3.14;
o D) float num = 3,14;

Answer: A) float num;

9. What is the purpose of the return keyword in a function?


o A) To end the program
o B) To return a value to the calling function
o C) To declare a variable
o D) To include header files

Answer: B) To return a value to the calling function

10. Which of the following is a reserved keyword in C?


o A) variable
o B) for
o C) func
o D) doWhile

Answer: B) for

Values, Names, Scope, Binding, and Storage Classes in C

1. What is the primary purpose of a variable name in C?


o A) To store data permanently
o B) To represent a memory location
o C) To perform calculations
o D) To format output

Answer: B) To represent a memory location

2. Which of the following storage classes has the widest scope and lifetime throughout
the program?
o A) auto
o B) register
o C) static
o D) extern

Answer: D) extern

3. What is the scope of a variable declared inside a function?


o A) Global scope
o B) Local scope
o C) File scope
o D) Block scope

Answer: B) Local scope

4. What keyword is used to declare a variable that retains its value even after the
function exits?
o A) auto
o B) static
o C) extern
o D) const
Answer: B) static

5. Which storage class limits the visibility of a variable to the block in which it is
defined?
o A) extern
o B) static
o C) auto
o D) register

Answer: C) auto

6. What is the default storage class for a variable declared inside a function without an
explicit storage class?
o A) extern
o B) static
o C) auto
o D) register

Answer: C) auto

7. Which of the following is true about 'static' variables?


o A) They are automatically initialized.
o B) Their scope is global.
o C) They retain their value between function calls.
o D) They cannot be declared inside functions.

Answer: C) They retain their value between function calls.

8. What is the binding of a variable in C?


o A) The method of variable initialization
o B) The association of a variable with its value and type
o C) The scope of the variable
o D) The lifetime of the variable

Answer: B) The association of a variable with its value and type

9. What is the main purpose of using 'register' storage class?


o A) To keep variables in the memory permanently
o B) To suggest that a variable should be stored in a CPU register for faster access
o C) To make the variable accessible across multiple files
o D) To maintain the variable's state between function calls

Answer: B) To suggest that a variable should be stored in a CPU register for faster
access

10. Which of the following correctly describes the concept of variable scope?
o A) It defines the type of data the variable can hold.
o B) It determines the lifespan of the variable.
o C) It defines the region of the program where the variable can be accessed.
o D) It specifies how much memory the variable will use.

Answer: C) It defines the region of the program where the variable can be accessed.

Numeric and Non-Numeric Data Types in C

1. Which of the following is a numeric data type in C?


o A) char
o B) int
o C) float
o D) All of the above

Answer: D) All of the above

2. What is the range of the int data type in C (typically on a 32-bit system)?
o A) -32,768 to 32,767
o B) -2,147,483,648 to 2,147,483,647
o C) 0 to 65,535
o D) -1.7 billion to 1.7 billion

Answer: B) -2,147,483,648 to 2,147,483,647

3. Which of the following is a non-numeric data type in C?


o A) float
o B) char
o C) double
o D) int

Answer: B) char

4. What data type is used to store a decimal value in C?


o A) int
o B) char
o C) float
o D) void

Answer: C) float

5. Which of the following is true about the double data type in C?


o A) It occupies less memory than float.
o B) It is used for storing integer values.
o C) It provides higher precision for floating-point numbers.
o D) It cannot represent decimal values.

Answer: C) It provides higher precision for floating-point numbers.

6. What is the default value of an uninitialized int variable in C?


o A) 0
o B) Undefined
o C) NULL
o D) 1

Answer: B) Undefined

7. Which data type can store a wide character in C?


o A) char
o B) wchar_t
o C) int
o D) float

Answer: B) wchar_t

8. What is the purpose of the sizeof operator in C?


o A) To determine the size of a variable's value
o B) To count the number of elements in an array
o C) To determine the size in bytes of a data type or variable
o D) To allocate memory for a variable

Answer: C) To determine the size in bytes of a data type or variable

9. Which data type is best suited for representing boolean values in C?


o A) int
o B) char
o C) bool
o D) Both A and B

Answer: D) Both A and B (Note: The bool type is available in C99 and later; otherwise,
int is often used for boolean values.)

10. What will the following code output?

c
Copy code
printf("%d", sizeof(char));

o A) 1
o B) 2
o C) 4
o D) Depends on the system

Answer: A) 1

Lvalues and Rvalues in C

1. What is an lvalue in C?
o A) A value that can appear on the left side of an assignment
o B) A constant value that cannot change
o C) A temporary value that cannot be referenced
o D) A type of function

Answer: A) A value that can appear on the left side of an assignment

2. What is an rvalue in C?
o A) A value that can appear on the right side of an assignment
o B) A variable that can be modified
o C) A type of data structure
o D) A reference to a variable

Answer: A) A value that can appear on the right side of an assignment

3. Which of the following is an example of an lvalue?


o A) 42
o B) x + y
o C) int a;
o D) a + 10

Answer: C) int a;

4. Which of the following is an example of an rvalue?


o A) x
o B) y + 1
o C) 100
o D) Both B and C

Answer: D) Both B and C

5. What happens if you try to assign a value to an rvalue?


o A) It compiles without errors.
o B) It results in a compilation error.
o C) It creates a temporary variable.
o D) It has no effect.
Answer: B) It results in a compilation error.

6. In the expression x = 5 + y, which part is the lvalue?


o A) 5
o B) y
o C) x
o D) 5 + y

Answer: C) x

7. Can an rvalue be assigned to a pointer?


o A) Yes, always.
o B) No, never.
o C) Only if the rvalue is a variable.
o D) Only if the rvalue is a constant.

Answer: A) Yes, always.

8. Which of the following statements is TRUE regarding lvalues and rvalues?


o A) An lvalue can always be converted to an rvalue.
o B) An rvalue can always be converted to an lvalue.
o C) Both lvalues and rvalues can be assigned to each other.
o D) Lvalues can only be constants.

Answer: A) An lvalue can always be converted to an rvalue.

9. In the context of function arguments, which of the following would be considered an


rvalue?
o A) An array
o B) A literal value like 3.14
o C) A variable
o D) A pointer

Answer: B) A literal value like 3.14

10. Which of the following is NOT an example of an lvalue?


o A) A variable
o B) An array element
o C) A function call that returns a reference
o D) A literal integer

Answer: D) A literal integer

Operators in C Language
1. Which operator is used for addition in C?
o A) -
o B) *
o C) /
o D) +

Answer: D) +

2. What will be the output of the following code?

c
Copy code
int a = 10, b = 5;
printf("%d", a % b);

o A) 2
o B) 5
o C) 0
o D) 10

Answer: B) 0

3. Which of the following operators has the highest precedence in C?


o A) +
o B) *
o C) -
o D) /

Answer: B) *

4. What is the result of the expression 3 + 4 * 2 in C?


o A) 14
o B) 11
o C) 10
o D) 8

Answer: B) 11

5. What is the output of the following code?

c
Copy code
int x = 5;
int y = x++;
printf("%d", y);

o A) 5
o B) 6
o C) 4
o D) 0

Answer: A) 5

6. Which operator is used for logical AND in C?


o A) &
o B) &&
o C) ||
o D) !

Answer: B) &&

7. What does the sizeof operator return?


o A) The size of a variable in bits
o B) The size of a variable in bytes
o C) The maximum value a variable can hold
o D) The number of elements in an array

Answer: B) The size of a variable in bytes

8. Which operator is used to access a member of a structure?


o A) .
o B) ->
o C) ::
o D) Both A and B

Answer: D) Both A and B

9. What will be the output of the following code?

c
Copy code
int a = 10;
int b = 20;
printf("%d", (a > b) ? a : b);

o A) 10
o B) 20
o C) 0
o D) 1

Answer: B) 20

10. Which of the following is NOT a relational operator in C?


o A) ==
o B) <=
o C) :=
o D) >

Answer: C) :=

 What is the result of the following code snippet?

c
Copy code
int a = 5;
a++;
printf("%d", a);

 A) 5
 B) 6
 C) 4
 D) 7

Answer: B) 6

 Which operator is used to decrement a variable by 1 in C?

 A) --
 B) -=
 C) ++
 D) -=1

Answer: A) --

 What does the following expression evaluate to?

c
Copy code
int x = 10;
int y = 20;
int z = (x++, y);
printf("%d", z);

 A) 10
 B) 20
 C) 30
 D) 0

Answer: B) 20

 What is the purpose of the arrow operator (->) in C?


 A) To dereference a pointer to a structure
 B) To define a pointer
 C) To increment a value
 D) To compare two values

Answer: A) To dereference a pointer to a structure

 What will the following code output?

c
Copy code
struct Point {
int x;
int y;
};
struct Point p = {1, 2};
struct Point *ptr = &p;
printf("%d", ptr->y);

 A) 1
 B) 2
 C) 0
 D) Compilation error

Answer: B) 2

 Which of the following is a correct way to assign the value of one variable to another?

 A) a = b;
 B) a := b;
 C) a <-> b;
 D) a -> b;

Answer: A) a = b;

 What will be the result of the following code?

c
Copy code
int a = 3;
int b = 4;
int c = a++ + ++b;
printf("%d", c);

 A) 6
 B) 7
 C) 8
 D) 11

Answer: C) 8

 Which operator can combine multiple expressions into a single statement?

 A) ;
 B) :
 C) ,
 D) &

Answer: C) ,

 What is the result of the following code?

c
Copy code
int a = 5;
a += 2; // Equivalent to a = a + 2;
printf("%d", a);

 A) 5
 B) 6
 C) 7
 D) 8

Answer: C) 7

 In the expression x = (a++, b), what will x be assigned?

 A) The value of a
 B) The value of b
 C) The sum of a and b
 D) The result of a++

Answer: B) The value of b

You might also like