WBSSC SLST Computer Application IX & X : Programming Language

Programming Language MCQs (C & OOP)

(a) C-Language

Basics, Keywords, Variables

1. Which of the following is not a valid keyword in C?
নিচের কোনটি C-তে একটি বৈধ কীওয়ার্ড নয়?

  • A) auto
  • B) main
  • C) static
  • D) extern

Correct Answer: B) main

Explanation: `main` is a standard function name in C, which acts as the entry point of a program, but it is not a reserved keyword. `auto`, `static`, and `extern` are all valid C keywords used as storage class specifiers.

ব্যাখ্যা: `main` C-তে একটি স্ট্যান্ডার্ড ফাংশনের নাম, যা প্রোগ্রামের এন্ট্রি পয়েন্ট হিসাবে কাজ করে, কিন্তু এটি কোনো সংরক্ষিত কীওয়ার্ড নয়। `auto`, `static`, এবং `extern` সবই বৈধ C কীওয়ার্ড যা স্টোরেজ ক্লাস স্পেসিফায়ার হিসেবে ব্যবহৃত হয়।

2. What is the size of `int` data type in a 32-bit compiler in C?
C-তে একটি 32-বিট কম্পাইলারে `int` ডেটা টাইপের সাইজ কত?

  • A) 1 Byte
  • B) 2 Bytes
  • C) 4 Bytes
  • D) 8 Bytes

Correct Answer: C) 4 Bytes

Explanation: The size of data types in C can be compiler-dependent. However, on a typical 32-bit compiler, an `int` data type occupies 4 bytes (32 bits) of memory.

ব্যাখ্যা: C-তে ডেটা টাইপের সাইজ কম্পাইলার-নির্ভর হতে পারে। তবে, একটি সাধারণ 32-বিট কম্পাইলারে, একটি `int` ডেটা টাইপ 4 বাইট (32 বিট) মেমরি নেয়।

3. Which of the following is a valid identifier in C?
নিচের কোনটি C-তে একটি বৈধ আইডেন্টিফায়ার?

  • A) 1st_variable
  • B) _myvariable
  • C) int
  • D) my-variable

Correct Answer: B) _myvariable

Explanation: An identifier in C can start with a letter (a-z, A-Z) or an underscore (_), followed by letters, digits, or underscores. It cannot start with a digit (like A), be a keyword (like C), or contain special characters like hyphen (like D).

ব্যাখ্যা: C-তে একটি আইডেন্টিফায়ার একটি অক্ষর (a-z, A-Z) বা একটি আন্ডারস্কোর (_) দিয়ে শুরু হতে পারে, এবং তারপরে অক্ষর, সংখ্যা বা আন্ডারস্কোর থাকতে পারে। এটি কোনো সংখ্যা দিয়ে শুরু হতে পারে না (যেমন A), কোনো কীওয়ার্ড হতে পারে না (যেমন C), বা হাইফেনের মতো বিশেষ অক্ষর থাকতে পারে না (যেমন D)।

4. What does the `const` keyword do?
`const` কীওয়ার্ড কী কাজ করে?

  • A) Makes a variable’s value unmodifiable.
  • B) Declares a constant pointer.
  • C) Allocates static memory.
  • D) Defines a global variable.

Correct Answer: A) Makes a variable’s value unmodifiable.

Explanation: The `const` keyword is a qualifier that, when applied to a variable declaration, specifies that the variable’s value cannot be changed after its initial assignment.

ব্যাখ্যা: `const` কীওয়ার্ড একটি কোয়ালিফায়ার যা একটি ভেরিয়েবল ডিক্লারেশনে প্রয়োগ করা হলে, এটি নির্দিষ্ট করে যে ভেরিয়েবলের মান তার প্রাথমিক অ্যাসাইনমেন্টের পরে পরিবর্তন করা যাবে না।

5. The basic structure of a C program consists of…
একটি C প্রোগ্রামের মৌলিক কাঠামোতে কী কী থাকে…

  • A) Preprocessor Directives, Global Declarations, main() function, User-defined functions.
  • B) Only the main() function.
  • C) Header files and a list of variables.
  • D) Class definitions and objects.

Correct Answer: A) Preprocessor Directives, Global Declarations, main() function, User-defined functions.

Explanation: A typical C program structure includes preprocessor directives (like `#include`), optional global declarations, the mandatory `main()` function where execution begins, and optional user-defined functions.

ব্যাখ্যা: একটি সাধারণ C প্রোগ্রামের কাঠামোতে প্রিপ্রসেসর ডিরেক্টিভ (যেমন `#include`), ঐচ্ছিক গ্লোবাল ডিক্লারেশন, বাধ্যতামূলক `main()` ফাংশন যেখান থেকে এক্সিকিউশন শুরু হয়, এবং ঐচ্ছিক ব্যবহারকারী-সংজ্ঞায়িত ফাংশন অন্তর্ভুক্ত থাকে।

Operators

6. What is the output of the expression `5 + 3 * 2 % 3`?
`5 + 3 * 2 % 3` এক্সপ্রেশনটির আউটপুট কী?

  • A) 2
  • B) 5
  • C) 6
  • D) 0

Correct Answer: B) 5

Explanation: Due to operator precedence, `*` and `%` are evaluated before `+`. They have the same precedence, so they are evaluated from left to right.
1. `3 * 2` = 6
2. `6 % 3` = 0 (remainder of 6 divided by 3)
3. `5 + 0` = 5

ব্যাখ্যা: অপারেটরের অগ্রাধিকারের কারণে, `+` এর আগে `*` এবং `%` এর কাজ হবে। তাদের অগ্রাধিকার সমান, তাই তারা বাম থেকে ডানে কাজ করবে।
১. `3 * 2` = 6
২. `6 % 3` = 0 (6 কে 3 দ্বারা ভাগ করলে ভাগশেষ)
৩. `5 + 0` = 5

7. Which operator is known as the ternary or conditional operator?
কোন অপারেটরটি টারনারি বা কন্ডিশনাল অপারেটর হিসাবে পরিচিত?

  • A) `&&`
  • B) `||`
  • C) `?:`
  • D) `==`

Correct Answer: C) `?:`

Explanation: The `?:` operator is the conditional operator in C. It takes three operands. The syntax is `condition ? value_if_true : value_if_false`.

ব্যাখ্যা: `?:` অপারেটরটি C-তে কন্ডিশনাল অপারেটর। এটি তিনটি অপারেন্ড নেয়। এর সিনট্যাক্স হল `condition ? value_if_true : value_if_false`।

8. What is the result of `x` after the following code? `int x = 10; x = x++;`
নিচের কোডের পরে `x` এর মান কী হবে? `int x = 10; x = x++;`

  • A) 9
  • B) 10
  • C) 11
  • D) Undefined Behavior

Correct Answer: D) Undefined Behavior

Explanation: Modifying a variable more than once between two sequence points results in undefined behavior in C. In `x = x++`, the variable `x` is both being assigned to and modified (by `++`) without an intervening sequence point. The result is not guaranteed and can vary between compilers.

ব্যাখ্যা: C-তে দুটি সিকোয়েন্স পয়েন্টের মধ্যে একটি ভেরিয়েবলকে একাধিকবার পরিবর্তন করলে এটি আনডিফাইন্ড বিহেভিয়ার (অনির্দিষ্ট আচরণ) ঘটায়। `x = x++` এ, `x` ভেরিয়েবলটিকে অ্যাসাইন করা হচ্ছে এবং `++` দ্বারা পরিবর্তনও করা হচ্ছে, যার মধ্যে কোনো সিকোয়েন্স পয়েন্ট নেই। এর ফলাফল নিশ্চিত নয় এবং বিভিন্ন কম্পাইলারে ভিন্ন হতে পারে।

9. The `==` operator is a…
`==` অপারেটরটি একটি…

  • A) Logical Operator
  • B) Relational Operator
  • C) Assignment Operator
  • D) Bitwise Operator

Correct Answer: B) Relational Operator

Explanation: The `==` operator is a relational operator used to check if two operands are equal. It returns `1` (true) if they are equal, and `0` (false) otherwise. The `=` operator is the assignment operator.

ব্যাখ্যা: `==` অপারেটরটি একটি রিলেশনাল অপারেটর যা দুটি অপারেন্ড সমান কিনা তা পরীক্ষা করতে ব্যবহৃত হয়। যদি তারা সমান হয় তবে এটি `1` (সত্য) প্রদান করে, অন্যথায় `0` (মিথ্যা) প্রদান করে। `=` অপারেটরটি হল অ্যাসাইনমেন্ট অপারেটর।

10. Which operator has the highest precedence in C?
C-তে কোন অপারেটরের অগ্রাধিকার সর্বোচ্চ?

  • A) `()` (Function call)
  • B) `*` (Multiplication)
  • C) `+` (Addition)
  • D) `=` (Assignment)

Correct Answer: A) `()` (Function call)

Explanation: Parentheses `()` for function calls and grouping, and brackets `[]` for array subscripting have the highest precedence among all operators in C.

ব্যাখ্যা: ফাংশন কল এবং গ্রুপিংয়ের জন্য প্যারেনথেসিস `()` এবং অ্যারে সাবস্ক্রিপ্টিংয়ের জন্য ব্র্যাকেট `[]` C-তে সমস্ত অপারেটরের মধ্যে সর্বোচ্চ অগ্রাধিকার পায়।

Input/Output, Branching & Looping

11. Which function is used for formatted input in C?
C-তে ফরম্যাটেড ইনপুটের জন্য কোন ফাংশন ব্যবহার করা হয়?

  • A) `printf()`
  • B) `scanf()`
  • C) `gets()`
  • D) `puts()`

Correct Answer: B) `scanf()`

Explanation: `scanf()` is the standard library function used to read formatted input from the standard input (usually the keyboard).

ব্যাখ্যা: `scanf()` হল একটি স্ট্যান্ডার্ড লাইব্রেরি ফাংশন যা স্ট্যান্ডার্ড ইনপুট (সাধারণত কীবোর্ড) থেকে ফরম্যাটেড ইনপুট পড়ার জন্য ব্যবহৃত হয়।

12. What will be printed by the following code? `for(int i=0; i<3; i++); printf("%d", i);`
নিচের কোডটি কী প্রিন্ট করবে? `for(int i=0; i<3; i++); printf("%d", i);`

  • A) 012
  • B) 3
  • C) Compile Error
  • D) 0

Correct Answer: C) Compile Error

Explanation: There are two issues. First, the semicolon `;` after the `for` loop makes it an empty loop. The loop runs for i=0, 1, 2 and then terminates when i becomes 3. The second, more critical issue is that the variable `i` is declared inside the `for` loop (a feature from C99 onwards). Its scope is limited to the loop itself. The `printf` statement is outside this scope, thus it cannot access `i`, leading to a compile error.

ব্যাখ্যা: এখানে দুটি সমস্যা আছে। প্রথমত, `for` লুপের পরে সেমিকোলন `;` এটিকে একটি খালি লুপে পরিণত করে। লুপটি i=0, 1, 2 এর জন্য চলে এবং যখন i এর মান 3 হয় তখন শেষ হয়। দ্বিতীয় এবং সবচেয়ে গুরুত্বপূর্ণ সমস্যাটি হল, `i` ভেরিয়েবলটি `for` লুপের ভিতরে ঘোষণা করা হয়েছে (C99 থেকে এই বৈশিষ্ট্যটি এসেছে)। এর স্কোপ শুধুমাত্র লুপের মধ্যেই সীমাবদ্ধ। `printf` স্টেটমেন্টটি এই স্কোপের বাইরে, তাই এটি `i` অ্যাক্সেস করতে পারে না, যার ফলে একটি কম্পাইল এরর হবে।

13. Which statement is used to terminate the current iteration and start the next iteration of a loop?
লুপের বর্তমান ইটারেশন শেষ করে পরবর্তী ইটারেশন শুরু করার জন্য কোন স্টেটমেন্ট ব্যবহার করা হয়?

  • A) `break`
  • B) `exit()`
  • C) `return`
  • D) `continue`

Correct Answer: D) `continue`

Explanation: The `continue` statement skips the rest of the code inside the loop for the current iteration and proceeds to the next iteration. `break` terminates the entire loop. `exit()` terminates the entire program. `return` exits the current function.

ব্যাখ্যা: `continue` স্টেটমেন্টটি বর্তমান ইটারেশনের জন্য লুপের ভিতরের বাকি কোড এড়িয়ে যায় এবং পরবর্তী ইটারেশনে চলে যায়। `break` পুরো লুপটি শেষ করে দেয়। `exit()` পুরো প্রোগ্রামটি শেষ করে। `return` বর্তমান ফাংশন থেকে বেরিয়ে আসে।

14. In a `switch` statement, what is the purpose of the `default` case?
একটি `switch` স্টেটমেন্টে, `default` কেসের উদ্দেশ্য কী?

  • A) It is mandatory in every switch statement.
  • B) It executes when none of the other case labels match the switch expression.
  • C) It must be the last case in the switch block.
  • D) It is used to declare a default variable.

Correct Answer: B) It executes when none of the other case labels match the switch expression.

Explanation: The `default` case is optional and acts as a catch-all. If the value of the switch expression does not match any of the `case` constants, the code block under `default` is executed.

ব্যাখ্যা: `default` কেসটি ঐচ্ছিক এবং একটি ক্যাচ-অল হিসাবে কাজ করে। যদি সুইচ এক্সপ্রেশনের মান কোনো `case` কনস্ট্যান্টের সাথে না মেলে, তাহলে `default`-এর অধীনে থাকা কোড ব্লকটি কার্যকর হয়।

15. Which loop is guaranteed to execute at least once?
কোন লুপটি অন্তত একবার কার্যকর হবেই?

  • A) `for` loop
  • B) `while` loop
  • C) `do-while` loop
  • D) `if-else` loop

Correct Answer: C) `do-while` loop

Explanation: A `do-while` loop is an exit-controlled loop, meaning it evaluates its condition at the end of the loop body. Therefore, the loop body is always executed at least once, regardless of whether the condition is true or false.

ব্যাখ্যা: একটি `do-while` লুপ একটি এক্সিট-কন্ট্রোলড লুপ, যার অর্থ এটি লুপ বডির শেষে তার কন্ডিশন পরীক্ষা করে। তাই, কন্ডিশন সত্য বা মিথ্যা যাই হোক না কেন, লুপ বডি সবসময় অন্তত একবার কার্যকর হয়।

Arrays

16. How do you declare a one-dimensional integer array named `scores` of size 10?
আপনি কিভাবে 10 সাইজের `scores` নামের একটি এক-মাত্রিক পূর্ণসংখ্যা অ্যারে ঘোষণা করবেন?

  • A) `array int scores[10];`
  • B) `int scores[10];`
  • C) `int scores; scores = new int[10];`
  • D) `scores[10] of int;`

Correct Answer: B) `int scores[10];`

Explanation: The correct syntax for declaring an array in C is `data_type array_name[size];`. Therefore, `int scores[10];` correctly declares an integer array named `scores` that can hold 10 elements.

ব্যাখ্যা: C-তে একটি অ্যারে ঘোষণা করার সঠিক সিনট্যাক্স হল `data_type array_name[size];`। অতএব, `int scores[10];` সঠিকভাবে `scores` নামের একটি পূর্ণসংখ্যা অ্যারে ঘোষণা করে যা 10টি উপাদান ধারণ করতে পারে।

17. If an array is declared as `int arr[5] = {10, 20, 30, 40, 50};`, what is the value of `arr[2]`?
যদি একটি অ্যারে `int arr[5] = {10, 20, 30, 40, 50};` হিসাবে ঘোষণা করা হয়, তাহলে `arr[2]` এর মান কত?

  • A) 20
  • B) 30
  • C) 40
  • D) Undefined

Correct Answer: B) 30

Explanation: Array indexing in C is 0-based. This means the first element is at index 0, the second at index 1, and so on. Therefore, `arr[2]` refers to the third element in the array, which is 30.

ব্যাখ্যা: C-তে অ্যারে ইনডেক্সিং 0-ভিত্তিক। এর মানে হল প্রথম উপাদানটি ইনডেক্স 0-তে, দ্বিতীয়টি ইনডেক্স 1-এ, এবং এইভাবে চলতে থাকে। অতএব, `arr[2]` অ্যারের তৃতীয় উপাদানকে বোঝায়, যার মান 30।

18. How are the elements of a 2D array stored in memory?
একটি 2D অ্যারের উপাদানগুলো মেমরিতে কীভাবে সংরক্ষিত হয়?

  • A) Column by column (column-major order)
  • B) Row by row (row-major order)
  • C) In a tree-like structure
  • D) Randomly

Correct Answer: B) Row by row (row-major order)

Explanation: C language stores multi-dimensional arrays in row-major order. This means all elements of the first row are stored contiguously in memory, followed by all elements of the second row, and so on.

ব্যাখ্যা: C ল্যাঙ্গুয়েজ বহু-মাত্রিক অ্যারেগুলিকে রো-মেজর অর্ডারে সংরক্ষণ করে। এর মানে হল প্রথম সারির সমস্ত উপাদান মেমরিতে একরৈখিকভাবে সংরক্ষিত হয়, তারপরে দ্বিতীয় সারির সমস্ত উপাদান, এবং এইভাবে চলতে থাকে।

19. What does `sizeof(arr)` return for `char arr[10];`?
`char arr[10];` এর জন্য `sizeof(arr)` কী রিটার্ন করবে?

  • A) 1
  • B) 10
  • C) 4
  • D) Depends on compiler

Correct Answer: B) 10

Explanation: The `sizeof` operator, when applied to a statically declared array, returns the total size of the array in bytes. Since a `char` is guaranteed to be 1 byte and the array has 10 elements, the total size is `10 * 1 = 10` bytes.

ব্যাখ্যা: `sizeof` অপারেটর, যখন একটি স্ট্যাটিক্যালি ডিক্লেয়ার করা অ্যারেতে প্রয়োগ করা হয়, তখন অ্যারের মোট সাইজ বাইটে রিটার্ন করে। যেহেতু একটি `char` এর সাইজ 1 বাইট এবং অ্যারেটিতে 10টি উপাদান রয়েছে, তাই মোট সাইজ `10 * 1 = 10` বাইট।

20. The name of an array (e.g., `arr` from `int arr[10]`) acts as a…
একটি অ্যারের নাম (যেমন, `int arr[10]` থেকে `arr`) কী হিসাবে কাজ করে?

  • A) Pointer to the first element of the array.
  • B) The value of the first element.
  • C) The size of the array.
  • D) A pointer to the last element of the array.

Correct Answer: A) Pointer to the first element of the array.

Explanation: In most contexts, the name of an array decays into a pointer to its first element. So, `arr` is equivalent to `&arr[0]`.

ব্যাখ্যা: বেশিরভাগ ক্ষেত্রে, একটি অ্যারের নাম তার প্রথম উপাদানের একটি পয়েন্টারে রূপান্তরিত হয়। সুতরাং, `arr` এবং `&arr[0]` সমতুল্য।

Pointers

21. Which operator is used to get the memory address of a variable?
একটি ভেরিয়েবলের মেমরি অ্যাড্রেস পেতে কোন অপারেটর ব্যবহার করা হয়?

  • A) `*`
  • B) `&`
  • C) `->`
  • D) `.`

Correct Answer: B) `&`

Explanation: The `&` operator is the “address-of” operator. It returns the memory address of its operand. For example, `&var` gives the address of the variable `var`.

ব্যাখ্যা: `&` অপারেটর হল “অ্যাড্রেস-অফ” অপারেটর। এটি তার অপারেন্ডের মেমরি অ্যাড্রেস রিটার্ন করে। উদাহরণস্বরূপ, `&var` ভেরিয়েবল `var` এর অ্যাড্রেস দেয়।

22. A pointer that is pointing to NOTHING is called a…
একটি পয়েন্টার যা কিছুকেই নির্দেশ করে না তাকে কী বলা হয়?

  • A) VOID pointer
  • B) DANGLING pointer
  • C) NULL pointer
  • D) WILD pointer

Correct Answer: C) NULL pointer

Explanation: A NULL pointer is a special pointer that is guaranteed not to point to any valid memory location. It is typically defined as `(void*)0` and is used to signify that a pointer doesn’t have a target.

ব্যাখ্যা: একটি NULL পয়েন্টার একটি বিশেষ পয়েন্টার যা কোনো বৈধ মেমরি লোকেশনকে নির্দেশ করে না। এটি সাধারণত `(void*)0` হিসাবে সংজ্ঞায়িত করা হয় এবং এটি বোঝাতে ব্যবহৃত হয় যে একটি পয়েন্টারের কোনো লক্ষ্য নেই।

23. What is the output of the following code? `int a = 10; int *p = &a; printf(“%d”, *p);`
নিচের কোডটির আউটপুট কী? `int a = 10; int *p = &a; printf(“%d”, *p);`

  • A) Address of `a`
  • B) 10
  • C) Address of `p`
  • D) Garbage value

Correct Answer: B) 10

Explanation: Here, `p` stores the address of `a`. The `*` operator, when used with a pointer (`*p`), is the dereferencing or indirection operator. It fetches the value stored at the address the pointer is pointing to. So, `*p` fetches the value of `a`, which is 10.

ব্যাখ্যা: এখানে, `p` পয়েন্টারটি `a` এর অ্যাড্রেস ধারণ করে। `*` অপারেটর, যখন একটি পয়েন্টারের সাথে ব্যবহৃত হয় (`*p`), তখন এটি ডিফেরেন্সিং বা ইনডাইরেকশন অপারেটর। এটি পয়েন্টার যে অ্যাড্রেসটিকে নির্দেশ করছে, সেই অ্যাড্রেসে সংরক্ষিত মানটি নিয়ে আসে। সুতরাং, `*p` ভেরিয়েবল `a` এর মান নিয়ে আসে, যা 10।

24. What is a dangling pointer?
ড্যাংলিং পয়েন্টার কী?

  • A) A pointer that has not been initialized.
  • B) A pointer that points to a memory location that has been deallocated or freed.
  • C) A pointer that points to the starting address of the program.
  • D) Another name for a NULL pointer.

Correct Answer: B) A pointer that points to a memory location that has been deallocated or freed.

Explanation: A dangling pointer arises when a pointer continues to point to a memory address after the memory at that location has been freed (e.g., using `free()`) or has gone out of scope. Accessing a dangling pointer leads to undefined behavior.

ব্যাখ্যা: একটি ড্যাংলিং পয়েন্টার তৈরি হয় যখন একটি পয়েন্টার কোনো মেমরি অ্যাড্রেসকে নির্দেশ করতে থাকে, অথচ সেই লোকেশনের মেমরিটি `free()` ব্যবহার করে বা স্কোপের বাইরে চলে যাওয়ার কারণে ডিঅ্যালোকেট করা হয়েছে। একটি ড্যাংলিং পয়েন্টার অ্যাক্সেস করলে আনডিফাইন্ড বিহেভিয়ার ঘটে।

25. If `ptr` is an integer pointer, what does `ptr++` do?
যদি `ptr` একটি ইন্টিজার পয়েন্টার হয়, তাহলে `ptr++` কী করে?

  • A) Increments the value pointed to by `ptr`.
  • B) Increments the pointer `ptr` by 1 byte.
  • C) Increments the pointer `ptr` by the size of an integer.
  • D) It is an invalid operation.

Correct Answer: C) Increments the pointer `ptr` by the size of an integer.

Explanation: Pointer arithmetic is scaled by the size of the data type it points to. If `ptr` is an `int*` and an `int` is 4 bytes, `ptr++` will increment the address stored in `ptr` by 4, making it point to the next integer in memory.

ব্যাখ্যা: পয়েন্টার অ্যারিথমেটিক তার ডেটা টাইপের সাইজ অনুযায়ী স্কেল করা হয়। যদি `ptr` একটি `int*` হয় এবং একটি `int` এর সাইজ 4 বাইট হয়, তাহলে `ptr++` `ptr`-এ সংরক্ষিত অ্যাড্রেসটিকে 4 দ্বারা বৃদ্ধি করবে, যাতে এটি মেমরিতে পরবর্তী ইন্টিজারকে নির্দেশ করে।

Structure, Union & File Handling

26. Which keyword is used to define a structure in C?
C-তে একটি স্ট্রাকচার সংজ্ঞায়িত করতে কোন কীওয়ার্ড ব্যবহার করা হয়?

  • A) `struct`
  • B) `structure`
  • C) `record`
  • D) `object`

Correct Answer: A) `struct`

Explanation: The `struct` keyword is used in C to define a user-defined data type that groups together variables of different data types under a single name.

ব্যাখ্যা: C-তে `struct` কীওয়ার্ডটি একটি ব্যবহারকারী-সংজ্ঞায়িত ডেটা টাইপ সংজ্ঞায়িত করতে ব্যবহৃত হয় যা বিভিন্ন ডেটা টাইপের ভেরিয়েবলকে একটি একক নামের অধীনে গ্রুপ করে।

27. What is the main difference between a `structure` and a `union` in C?
C-তে `structure` এবং `union`-এর মধ্যে প্রধান পার্থক্য কী?

  • A) All members of a structure can be accessed at once, but only one member of a union can be accessed.
  • B) A structure allocates memory for all its members, while a union allocates memory for its largest member.
  • C) A structure can have functions, but a union cannot.
  • D) There is no difference.

Correct Answer: B) A structure allocates memory for all its members, while a union allocates memory for its largest member.

Explanation: In a structure, each member has its own distinct memory location. The total size is the sum of the sizes of its members (plus padding). In a union, all members share the same memory location. The total size is the size of the largest member.

ব্যাখ্যা: একটি স্ট্রাকচারে, প্রতিটি সদস্যের নিজস্ব আলাদা মেমরি অবস্থান থাকে। মোট সাইজ তার সদস্যদের সাইজের যোগফল (এবং প্যাডিং)। একটি ইউনিয়নে, সমস্ত সদস্য একই মেমরি অবস্থান শেয়ার করে। মোট সাইজ হল তার বৃহত্তম সদস্যের সাইজ।

28. Which mode for `fopen()` is used to open a text file for both reading and writing?
একটি টেক্সট ফাইল পড়া এবং লেখা উভয় কাজের জন্য খুলতে `fopen()` এর কোন মোড ব্যবহার করা হয়?

  • A) `”w”`
  • B) `”r”`
  • C) `”a+”`
  • D) `”r+”`

Correct Answer: D) `”r+”`

Explanation: `”r+”` opens a text file for both reading and writing. The file must exist. `”w+”` also opens for reading and writing, but it truncates the file to zero length if it exists or creates it if it doesn’t. `”a+”` opens for reading and appending (writing at the end).

ব্যাখ্যা: `”r+”` একটি টেক্সট ফাইল পড়া এবং লেখা উভয়ের জন্য খোলে। ফাইলটির অস্তিত্ব থাকতে হবে। `”w+”` ও পড়া এবং লেখার জন্য খোলে, কিন্তু যদি ফাইলটি থাকে তবে এটি ফাইলের দৈর্ঘ্য শূন্য করে দেয় অথবা না থাকলে তৈরি করে। `”a+”` পড়া এবং অ্যাপেন্ডিং (শেষে লেখা) করার জন্য খোলে।

29. How do you access a member `age` of a structure variable `s1`?
আপনি একটি স্ট্রাকচার ভেরিয়েবল `s1`-এর সদস্য `age`-কে কীভাবে অ্যাক্সেস করবেন?

  • A) `s1->age`
  • B) `s1.age`
  • C) `s1(age)`
  • D) `age(s1)`

Correct Answer: B) `s1.age`

Explanation: The dot `.` operator (member access operator) is used to access members of a structure or union variable directly. The arrow `->` operator is used when you have a pointer to a structure.

ব্যাখ্যা: ডট `.` অপারেটর (সদস্য অ্যাক্সেস অপারেটর) সরাসরি একটি স্ট্রাকচার বা ইউনিয়ন ভেরিয়েবলের সদস্যদের অ্যাক্সেস করতে ব্যবহৃত হয়। অ্যারো `->` অপারেটরটি ব্যবহৃত হয় যখন আপনার কাছে একটি স্ট্রাকচারের পয়েন্টার থাকে।

30. Which function is used to close a file that was opened using `fopen()`?
`fopen()` ব্যবহার করে খোলা একটি ফাইল বন্ধ করতে কোন ফাংশন ব্যবহার করা হয়?

  • A) `close()`
  • B) `fclose()`
  • C) `endfile()`
  • D) `fileclose()`

Correct Answer: B) `fclose()`

Explanation: The `fclose()` function is the standard library function in C used to close a file stream that was previously opened. It takes a `FILE*` pointer as an argument.

ব্যাখ্যা: `fclose()` ফাংশনটি C-তে স্ট্যান্ডার্ড লাইব্রেরি ফাংশন যা পূর্বে খোলা একটি ফাইল স্ট্রিম বন্ধ করতে ব্যবহৃত হয়। এটি একটি `FILE*` পয়েন্টারকে আর্গুমেন্ট হিসেবে নেয়।

31. What is the purpose of `#include `?
`#include ` এর উদ্দেশ্য কী?

  • A) It links the standard input/output library.
  • B) It includes the source code of `stdio.h` into the current file.
  • C) It defines standard variables.
  • D) It compiles the `stdio.h` file.

Correct Answer: B) It includes the source code of `stdio.h` into the current file.

Explanation: The `#include` directive is a preprocessor command that tells the compiler to include the contents of the specified file (in this case, `stdio.h`, the standard I/O header) at that point in the code. This makes the declarations of functions like `printf` and `scanf` available.

ব্যাখ্যা: `#include` ডিরেক্টিভ একটি প্রিপ্রসেসর কমান্ড যা কম্পাইলারকে নির্দিষ্ট ফাইলের (এই ক্ষেত্রে `stdio.h`, স্ট্যান্ডার্ড I/O হেডার) বিষয়বস্তু কোডের সেই স্থানে অন্তর্ভুক্ত করতে বলে। এটি `printf` এবং `scanf` এর মতো ফাংশনের ডিক্লারেশন উপলব্ধ করে।

32. A C variable cannot start with…
একটি C ভেরিয়েবল কী দিয়ে শুরু হতে পারে না?

  • A) An alphabet
  • B) A number
  • C) An underscore
  • D) Both A and C

Correct Answer: B) A number

Explanation: The rules for identifiers (including variable names) in C state that they must begin with a letter (a-z, A-Z) or an underscore (_). They cannot begin with a number.

ব্যাখ্যা: C-তে আইডেন্টিফায়ার (ভেরিয়েবলের নাম সহ) এর নিয়ম বলে যে সেগুলি একটি অক্ষর (a-z, A-Z) বা একটি আন্ডারস্কোর (_) দিয়ে শুরু হতে হবে। তারা কোনো সংখ্যা দিয়ে শুরু হতে পারে না।

33. What is the output of `printf(“%d”, 8/3);`?
`printf(“%d”, 8/3);` এর আউটপুট কী?

  • A) 2.66
  • B) 2
  • C) 3
  • D) Compile Error

Correct Answer: B) 2

Explanation: In C, when division is performed between two integers, the result is also an integer (integer division). The fractional part is truncated. So, 8 / 3 equals 2.

ব্যাখ্যা: C-তে, যখন দুটি পূর্ণসংখ্যার মধ্যে ভাগ করা হয়, তখন ফলাফলটিও একটি পূর্ণসংখ্যা হয় (ইন্টিজার ডিভিশন)। ভগ্নাংশ অংশটি বাদ দেওয়া হয়। সুতরাং, 8 / 3 সমান 2।

34. Which of the following is a logical operator?
নিচের কোনটি একটি লজিক্যাল অপারেটর?

  • A) `&`
  • B) `|`
  • C) `&&`
  • D) `=`

Correct Answer: C) `&&`

Explanation: `&&` is the logical AND operator. `&` and `|` are bitwise AND and OR operators, respectively. `=` is the assignment operator.

ব্যাখ্যা: `&&` হল লজিক্যাল AND অপারেটর। `&` এবং `|` যথাক্রমে বিটওয়াইজ AND এবং OR অপারেটর। `=` হল অ্যাসাইনমেন্ট অপারেটর।

35. What is the format specifier for printing a floating-point number?
একটি ফ্লোটিং-পয়েন্ট সংখ্যা প্রিন্ট করার জন্য ফরম্যাট স্পেসিফায়ার কী?

  • A) `%d`
  • B) `%c`
  • C) `%f`
  • D) `%s`

Correct Answer: C) `%f`

Explanation: `%f` is used for `float` and `double` types. `%d` is for integers, `%c` is for characters, and `%s` is for strings.

ব্যাখ্যা: `%f` `float` এবং `double` টাইপের জন্য ব্যবহৃত হয়। `%d` পূর্ণসংখ্যার জন্য, `%c` অক্ষরের জন্য এবং `%s` স্ট্রিংয়ের জন্য।

36. The `break` statement is used to exit from a…
`break` স্টেটমেন্টটি কী থেকে বের হওয়ার জন্য ব্যবহৃত হয়?

  • A) `if` statement
  • B) function
  • C) loop or `switch` statement
  • D) program

Correct Answer: C) loop or `switch` statement

Explanation: The `break` statement immediately terminates the innermost loop (`for`, `while`, `do-while`) or `switch` statement in which it appears.

ব্যাখ্যা: `break` স্টেটমেন্টটি যে লুপ (`for`, `while`, `do-while`) বা `switch` স্টেটমেন্টের ভিতরে থাকে, সেটিকে অবিলম্বে শেষ করে দেয়।

37. In a 2D array declaration `int matrix[3][4];`, how many elements can it store?
একটি 2D অ্যারে ডিক্লারেশন `int matrix[3][4];`-এ, এটি কতগুলো উপাদান সংরক্ষণ করতে পারে?

  • A) 3
  • B) 4
  • C) 7
  • D) 12

Correct Answer: D) 12

Explanation: The total number of elements in a 2D array is the product of its dimensions. Here, it is `3 * 4 = 12` elements.

ব্যাখ্যা: একটি 2D অ্যারের মোট উপাদানের সংখ্যা হল তার ডাইমেনশনগুলির গুণফল। এখানে, এটি `3 * 4 = 12` টি উপাদান।

38. What will be the output? `char str[] = “Hello”; printf(“%d”, sizeof(str));`
আউটপুট কী হবে? `char str[] = “Hello”; printf(“%d”, sizeof(str));`

  • A) 5
  • B) 6
  • C) Garbage value
  • D) Compile Error

Correct Answer: B) 6

Explanation: When a string literal is used to initialize a character array, a null terminator character `\0` is automatically appended at the end. “Hello” has 5 characters, plus the null terminator makes it 6. `sizeof()` returns the total allocated size, which is 6 bytes.

ব্যাখ্যা: যখন একটি স্ট্রিং লিটারেল একটি ক্যারেক্টার অ্যারে ইনিশিয়ালাইজ করতে ব্যবহৃত হয়, তখন শেষে একটি নাল টার্মিনেটর অক্ষর `\0` স্বয়ংক্রিয়ভাবে যুক্ত হয়। “Hello”-তে 5টি অক্ষর আছে, এবং নাল টার্মিনেটর সহ এটি 6 হয়। `sizeof()` মোট বরাদ্দকৃত আকার রিটার্ন করে, যা 6 বাইট।

39. A pointer of type `void*` can hold the address of…
`void*` টাইপের একটি পয়েন্টার কিসের অ্যাড্রেস ধারণ করতে পারে?

  • A) only `int` type variables.
  • B) only `char` type variables.
  • C) any type of variable.
  • D) no variable.

Correct Answer: C) any type of variable.

Explanation: A `void` pointer is a generic pointer that can hold the address of any data type. However, it cannot be dereferenced directly; it must first be cast to a specific pointer type.

ব্যাখ্যা: একটি `void` পয়েন্টার একটি জেনেরিক পয়েন্টার যা যেকোনো ডেটা টাইপের অ্যাড্রেস ধারণ করতে পারে। তবে, এটি সরাসরি ডিফেরেন্স করা যায় না; প্রথমে এটিকে একটি নির্দিষ্ট পয়েন্টার টাইপে কাস্ট করতে হবে।

40. If `ptr` is a pointer to a structure, which operator is used to access its members?
যদি `ptr` একটি স্ট্রাকচারের পয়েন্টার হয়, তবে এর সদস্যদের অ্যাক্সেস করতে কোন অপারেটর ব্যবহৃত হয়?

  • A) `.` (dot)
  • B) `&` (address-of)
  • C) `*` (dereference)
  • D) `->` (arrow)

Correct Answer: D) `->` (arrow)

Explanation: The arrow operator `->` is used to access the members of a structure or union when you have a pointer to it. `ptr->member` is equivalent to `(*ptr).member`.

ব্যাখ্যা: অ্যারো অপারেটর `->` একটি স্ট্রাকচার বা ইউনিয়নের সদস্যদের অ্যাক্সেস করতে ব্যবহৃত হয় যখন আপনার কাছে সেটির একটি পয়েন্টার থাকে। `ptr->member` এবং `(*ptr).member` সমতুল্য।

41. What does `fseek(fp, 0, SEEK_END);` do?
`fseek(fp, 0, SEEK_END);` কী কাজ করে?

  • A) Moves the file pointer to the beginning of the file.
  • B) Moves the file pointer to the end of the file.
  • C) Moves the file pointer 0 bytes from the current position.
  • D) Reads 0 bytes from the end of the file.

Correct Answer: B) Moves the file pointer to the end of the file.

Explanation: `fseek()` sets the file position indicator. `SEEK_END` specifies that the offset (0 in this case) is relative to the end of the file. So, this command moves the file pointer to the very end of the file.

ব্যাখ্যা: `fseek()` ফাইল পজিশন ইন্ডিকেটর সেট করে। `SEEK_END` নির্দিষ্ট করে যে অফসেট (এই ক্ষেত্রে 0) ফাইলের শেষ থেকে গণনা করা হবে। সুতরাং, এই কমান্ডটি ফাইল পয়েন্টারকে ফাইলের একেবারে শেষে নিয়ে যায়।

42. Size of a `union` is determined by the size of its…
একটি `union` এর সাইজ তার কিসের সাইজ দ্বারা নির্ধারিত হয়?

  • A) First member
  • B) Last member
  • C) Smallest member
  • D) Largest member

Correct Answer: D) Largest member

Explanation: A union allocates enough memory to hold its largest member. All members share this same memory space.

ব্যাখ্যা: একটি ইউনিয়ন তার বৃহত্তম সদস্যকে ধারণ করার জন্য যথেষ্ট মেমরি বরাদ্দ করে। সমস্ত সদস্য এই একই মেমরি স্পেস শেয়ার করে।

43. Which of the following is not a valid storage class in C?
নিচের কোনটি C-তে একটি বৈধ স্টোরেজ ক্লাস নয়?

  • A) `static`
  • B) `extern`
  • C) `dynamic`
  • D) `register`

Correct Answer: C) `dynamic`

Explanation: The four storage class specifiers in C are `auto`, `register`, `static`, and `extern`. `dynamic` is not a keyword or storage class in C, although dynamic memory allocation is a concept (done via `malloc`, `calloc`, etc.).

ব্যাখ্যা: C-তে চারটি স্টোরেজ ক্লাস স্পেসিফায়ার হল `auto`, `register`, `static`, এবং `extern`। `dynamic` C-তে কোনো কীওয়ার্ড বা স্টোরেজ ক্লাস নয়, যদিও ডাইনামিক মেমরি অ্যালোকেশন একটি ধারণা (যা `malloc`, `calloc` ইত্যাদির মাধ্যমে করা হয়)।

44. What is the value of `EOF`?
`EOF`-এর মান কী?

  • A) 0
  • B) 1
  • C) A non-zero positive integer
  • D) A negative integer, typically -1

Correct Answer: D) A negative integer, typically -1

Explanation: `EOF` stands for End-Of-File. It is a macro defined in `` that represents a value returned by file I/O functions to indicate that the end of the file has been reached. It’s guaranteed to be a negative integer, and is commonly -1.

ব্যাখ্যা: `EOF` মানে End-Of-File। এটি `` এ সংজ্ঞায়িত একটি ম্যাক্রো যা ফাইল I/O ফাংশন দ্বারা রিটার্ন করা একটি মানকে বোঝায়, যা নির্দেশ করে যে ফাইলের শেষ প্রান্তে পৌঁছানো গেছে। এটি একটি ঋণাত্মক পূর্ণসংখ্যা হতে বাধ্য, এবং সাধারণত এর মান -1 হয়।

45. What is the output? `int a=5, b=2; float c; c = a/b; printf(“%.2f”, c);`
আউটপুট কী হবে? `int a=5, b=2; float c; c = a/b; printf(“%.2f”, c);`

  • A) 2.50
  • B) 2.00
  • C) 2
  • D) 0.00

Correct Answer: B) 2.00

Explanation: The expression `a/b` involves two integers, so integer division is performed, resulting in `2`. This integer value `2` is then promoted to a float (`2.0`) and assigned to `c`. Finally, printing `c` with `%.2f` gives `2.00`. To get `2.50`, one of the operands should be a float, e.g., `c = (float)a / b;`.

ব্যাখ্যা: `a/b` এক্সপ্রেশনটিতে দুটি পূর্ণসংখ্যা রয়েছে, তাই ইন্টিজার ডিভিশন সম্পাদিত হয়, যার ফলাফল `2`। এই পূর্ণসংখ্যা মান `2` তারপর একটি ফ্লোটে (`2.0`) রূপান্তরিত হয় এবং `c`-কে অ্যাসাইন করা হয়। অবশেষে, `%.2f` দিয়ে `c` প্রিন্ট করলে `2.00` পাওয়া যায়। `2.50` পাওয়ার জন্য, একটি অপারেন্ডকে ফ্লোট হতে হবে, যেমন, `c = (float)a / b;`।

46. What does `char *str;` declare?
`char *str;` কী ঘোষণা করে?

  • A) A string named str.
  • B) An array of characters.
  • C) A pointer to a character.
  • D) A character named str.

Correct Answer: C) A pointer to a character.

Explanation: `char *str;` declares a variable named `str` that is a pointer to a `char`. While it is often used to point to the first character of a string, its fundamental declaration is that of a character pointer.

ব্যাখ্যা: `char *str;` `str` নামের একটি ভেরিয়েবল ঘোষণা করে যা একটি `char`-এর পয়েন্টার। যদিও এটি প্রায়শই একটি স্ট্রিংয়ের প্রথম অক্ষরকে নির্দেশ করতে ব্যবহৃত হয়, তবে এর মৌলিক ঘোষণাটি হল একটি ক্যারেক্টার পয়েন্টার।

47. The `typedef` keyword is used to…
`typedef` কীওয়ার্ডটি কীসের জন্য ব্যবহৃত হয়?

  • A) Define a new variable.
  • B) Create an alias or a new name for an existing data type.
  • C) Define a new function type.
  • D) Declare a macro.

Correct Answer: B) Create an alias or a new name for an existing data type.

Explanation: `typedef` allows you to give a new name to an existing data type. For example, `typedef unsigned long ulong;` lets you use `ulong` as a synonym for `unsigned long`, improving code readability.

ব্যাখ্যা: `typedef` আপনাকে একটি বিদ্যমান ডেটা টাইপের জন্য একটি নতুন নাম দিতে দেয়। উদাহরণস্বরূপ, `typedef unsigned long ulong;` আপনাকে `unsigned long`-এর প্রতিশব্দ হিসাবে `ulong` ব্যবহার করতে দেয়, যা কোডের পঠনযোগ্যতা বাড়ায়।

48. Which header file is required for using dynamic memory allocation functions like `malloc()`?
`malloc()`-এর মতো ডায়নামিক মেমরি অ্যালোকেশন ফাংশন ব্যবহার করার জন্য কোন হেডার ফাইলের প্রয়োজন?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Correct Answer: D) ``

Explanation: The Standard Library header file, ``, contains the declarations for dynamic memory management functions like `malloc()`, `calloc()`, `realloc()`, and `free()`.

ব্যাখ্যা: স্ট্যান্ডার্ড লাইব্রেরি হেডার ফাইল, ``, ডায়নামিক মেমরি ম্যানেজমেন্ট ফাংশন যেমন `malloc()`, `calloc()`, `realloc()`, এবং `free()` এর ডিক্লারেশন ধারণ করে।

49. What is the purpose of the `return 0;` statement in the `main` function?
`main` ফাংশনে `return 0;` স্টেটমেন্টের উদ্দেশ্য কী?

  • A) It is a syntax requirement and has no meaning.
  • B) It indicates that the program has terminated with an error.
  • C) It indicates that the program has executed successfully.
  • D) It returns the value 0 to the first variable declared in main.

Correct Answer: C) It indicates that the program has executed successfully.

Explanation: The return value from `main` is an exit status that is passed back to the operating system. By convention, a return value of `0` signifies successful execution, while a non-zero value typically indicates that an error occurred.

ব্যাখ্যা: `main` থেকে রিটার্ন করা মানটি একটি এক্সিট স্ট্যাটাস যা অপারেটিং সিস্টেমে ফিরে যায়। প্রচলিত নিয়ম অনুসারে, `0` রিটার্ন মান সফল এক্সিকিউশন বোঝায়, যখন একটি নন-জিরো মান সাধারণত একটি ত্রুটি ঘটেছে বলে নির্দেশ করে।

50. Which loop is faster in C, `while` or `for`?
C-তে কোন লুপটি দ্রুত, `while` নাকি `for`?

  • A) `while` is always faster.
  • B) `for` is always faster.
  • C) Both have similar performance characteristics.
  • D) It depends on the compiler optimization.

Correct Answer: C) Both have similar performance characteristics.

Explanation: Modern compilers are very good at optimization. A simple `for` loop and its equivalent `while` loop will almost always be compiled into identical or near-identical machine code. Therefore, there is no significant performance difference between them. Choice of which to use is based on readability and logic.

ব্যাখ্যা: আধুনিক কম্পাইলারগুলি অপ্টিমাইজেশনে খুব ভালো। একটি সাধারণ `for` লুপ এবং তার সমতুল্য `while` লুপ প্রায় সবসময়ই একই বা প্রায় একই মেশিন কোডে কম্পাইল করা হবে। অতএব, তাদের মধ্যে কোনো উল্লেখযোগ্য পারফরম্যান্স পার্থক্য নেই। কোনটি ব্যবহার করতে হবে তা পঠনযোগ্যতা এবং যুক্তির উপর ভিত্তি করে নির্বাচন করা হয়।

(b) Object-Oriented Programming (OOP)

Concept & Difference with POP

51. Which of the following is a primary concept of Object-Oriented Programming?
নিচের কোনটি অবজেক্ট-ওরিয়েন্টেড প্রোগ্রামিংয়ের একটি প্রাথমিক ধারণা?

  • A) Functions
  • B) Pointers
  • C) Inheritance
  • D) Global variables

Correct Answer: C) Inheritance

Explanation: The four main pillars of OOP are Encapsulation, Abstraction, Inheritance, and Polymorphism. Functions, pointers, and global variables are features of procedural languages like C, though they are also used in OOP languages.

ব্যাখ্যা: OOP-এর চারটি প্রধান স্তম্ভ হল এনক্যাপসুলেশন, অ্যাবস্ট্রাকশন, ইনহেরিটেন্স, এবং পলিমরফিজম। ফাংশন, পয়েন্টার এবং গ্লোবাল ভেরিয়েবল হল C-এর মতো প্রসিডিউরাল ল্যাঙ্গুয়েজের বৈশিষ্ট্য, যদিও সেগুলি OOP ল্যাঙ্গুয়েজেও ব্যবহৃত হয়।

52. What is the main focus of Procedure-Oriented Programming (POP)?
প্রসিডিউর-ওরিয়েন্টেড প্রোগ্রামিং (POP)-এর প্রধান ফোকাস কী?

  • A) Data security
  • B) Objects
  • C) Algorithms and functions to perform a task
  • D) Data hiding

Correct Answer: C) Algorithms and functions to perform a task

Explanation: POP, like C, focuses on the procedures or functions that operate on data. The primary concern is “how” to do something, broken down into a series of steps (functions). OOP, in contrast, focuses on the data (objects) and the methods that manipulate that data.

ব্যাখ্যা: POP, যেমন C, ডেটার উপর কাজ করা প্রসিডিউর বা ফাংশনের উপর ফোকাস করে। প্রধান উদ্বেগ হল “কীভাবে” কিছু করা যায়, যা বিভিন্ন ধাপে (ফাংশন) বিভক্ত থাকে। এর বিপরীতে, OOP ডেটা (অবজেক্ট) এবং সেই ডেটা ম্যানিপুলেট করা মেথডের উপর ফোকাস করে।

53. Which approach is typically “top-down”?
কোন অ্যাপ্রোচটি সাধারণত “টপ-ডাউন”?

  • A) Object-Oriented Programming
  • B) Procedure-Oriented Programming
  • C) Both A and B
  • D) Neither A nor B

Correct Answer: B) Procedure-Oriented Programming

Explanation: POP follows a top-down approach, where a large program is broken down into smaller, manageable functions. OOP follows a bottom-up approach, where basic objects are designed first and then used to build more complex systems.

ব্যাখ্যা: POP একটি টপ-ডাউন অ্যাপ্রোচ অনুসরণ করে, যেখানে একটি বড় প্রোগ্রামকে ছোট, পরিচালনাযোগ্য ফাংশনে বিভক্ত করা হয়। OOP একটি বটম-আপ অ্যাপ্রোচ অনুসরণ করে, যেখানে প্রথমে মৌলিক অবজেক্ট ডিজাইন করা হয় এবং তারপরে আরও জটিল সিস্টেম তৈরি করতে ব্যবহৃত হয়।

54. Which programming paradigm gives more importance to data over procedures?
কোন প্রোগ্রামিং প্যারাডাইম প্রসিডিউরের চেয়ে ডেটাকে বেশি গুরুত্ব দেয়?

  • A) Procedure-Oriented Programming (POP)
  • B) Object-Oriented Programming (OOP)
  • C) Functional Programming
  • D) Logical Programming

Correct Answer: B) Object-Oriented Programming (OOP)

Explanation: A fundamental shift in OOP is its focus on data. Data is encapsulated within objects and is protected from accidental modification by external functions. In POP, data is often global and can be accessed and modified freely by any function, making it less secure.

ব্যাখ্যা: OOP-এর একটি মৌলিক পরিবর্তন হল ডেটার উপর এর ফোকাস। ডেটা অবজেক্টের মধ্যে এনক্যাপসুলেটেড থাকে এবং বাহ্যিক ফাংশন দ্বারা আকস্মিক পরিবর্তন থেকে সুরক্ষিত থাকে। POP-তে, ডেটা প্রায়শই গ্লোবাল হয় এবং যেকোনো ফাংশন দ্বারা অবাধে অ্যাক্সেস ও পরিবর্তন করা যায়, যা এটিকে কম সুরক্ষিত করে তোলে।

55. Adding new data and functions is easier in which paradigm?
কোন প্যারাডাইমে নতুন ডেটা এবং ফাংশন যোগ করা সহজ?

  • A) Procedure-Oriented Programming
  • B) Object-Oriented Programming
  • C) Both are equally easy
  • D) Both are equally difficult

Correct Answer: B) Object-Oriented Programming

Explanation: OOP’s modular nature, based on classes, makes it easier to add new features. A new class can be created with its own data and functions without disturbing the existing classes, or a new class can inherit from an existing one, extending its functionality.

ব্যাখ্যা: OOP-এর মডুলার প্রকৃতি, যা ক্লাসের উপর ভিত্তি করে তৈরি, নতুন বৈশিষ্ট্য যোগ করা সহজ করে তোলে। বিদ্যমান ক্লাসগুলিকে বিরক্ত না করে নিজস্ব ডেটা এবং ফাংশন সহ একটি নতুন ক্লাস তৈরি করা যেতে পারে, অথবা একটি নতুন ক্লাস একটি বিদ্যমান ক্লাস থেকে ইনহেরিট করে তার কার্যকারিতা বাড়াতে পারে।

Data Abstraction, Object, Class, Methods

56. What is a Class in OOP?
OOP-তে ক্লাস কী?

  • A) An instance of an object.
  • B) A blueprint or template for creating objects.
  • C) A function that creates objects.
  • D) A data type of an object.

Correct Answer: B) A blueprint or template for creating objects.

Explanation: A class is a user-defined blueprint from which objects are created. It defines a set of attributes (data members) and methods (member functions) that the created objects will have.

ব্যাখ্যা: ক্লাস হল একটি ব্যবহারকারী-সংজ্ঞায়িত ব্লুপ্রিন্ট যা থেকে অবজেক্ট তৈরি করা হয়। এটি অ্যাট্রিবিউট (ডেটা মেম্বার) এবং মেথড (মেম্বার ফাংশন) এর একটি সেট সংজ্ঞায়িত করে যা তৈরি করা অবজেক্টগুলির থাকবে।

57. The process of hiding complex implementation details and showing only the essential features of an object is called…
জটিল বাস্তবায়নের বিবরণ লুকিয়ে রেখে এবং একটি অবজেক্টের শুধুমাত্র প্রয়োজনীয় বৈশিষ্ট্যগুলি দেখানোর প্রক্রিয়াকে কী বলা হয়?

  • A) Encapsulation
  • B) Inheritance
  • C) Polymorphism
  • D) Abstraction

Correct Answer: D) Abstraction

Explanation: Data Abstraction refers to the act of representing essential features without including the background details or explanations. It focuses on the “what” an object does, rather than “how” it does it.

ব্যাখ্যা: ডেটা অ্যাবস্ট্রাকশন বলতে பின்னணியের বিবরণ বা ব্যাখ্যা অন্তর্ভুক্ত না করে শুধুমাত্র অপরিহার্য বৈশিষ্ট্যগুলি উপস্থাপন করার কাজকে বোঝায়। এটি একটি অবজেক্ট “কী” করে তার উপর ফোকাস করে, “কীভাবে” করে তার উপর নয়।

58. An object is a(n)…
একটি অবজেক্ট হল একটি…

  • A) Member of a class.
  • B) Instance of a class.
  • C) Blueprint of a class.
  • D) A method of a class.

Correct Answer: B) Instance of a class.

Explanation: An object is a real-world entity and an instance of a class. When a class is defined, no memory is allocated, but when an object of that class is created (instantiated), memory is allocated.

ব্যাখ্যা: একটি অবজেক্ট একটি বাস্তব-বিশ্বের সত্তা এবং একটি ক্লাসের ইনস্ট্যান্স। যখন একটি ক্লাস সংজ্ঞায়িত করা হয়, তখন কোনো মেমরি বরাদ্দ করা হয় না, কিন্তু যখন সেই ক্লাসের একটি অবজেক্ট তৈরি করা হয় (ইনস্ট্যানশিয়েট করা হয়), তখন মেমরি বরাদ্দ করা হয়।

59. Functions defined inside a class are called…
একটি ক্লাসের ভিতরে সংজ্ঞায়িত ফাংশনগুলিকে কী বলা হয়?

  • A) Procedures
  • B) Friend functions
  • C) Methods or Member Functions
  • D) Class functions

Correct Answer: C) Methods or Member Functions

Explanation: In the context of OOP, functions that are part of a class are known as methods or member functions. They operate on the data members of the class’s objects.

ব্যাখ্যা: OOP-এর প্রেক্ষাপটে, যে ফাংশনগুলি একটি ক্লাসের অংশ, সেগুলি মেথড বা মেম্বার ফাংশন হিসাবে পরিচিত। তারা ক্লাসের অবজেক্টের ডেটা মেম্বারদের উপর কাজ করে।

60. Wrapping up data and methods into a single unit (a class) is known as…
ডেটা এবং মেথডকে একটি একক ইউনিটে (একটি ক্লাস) আবদ্ধ করাকে কী বলা হয়?

  • A) Abstraction
  • B) Encapsulation
  • C) Inheritance
  • D) Polymorphism

Correct Answer: B) Encapsulation

Explanation: Encapsulation is the bundling of data (attributes) and the methods that operate on that data into a single unit, or “capsule,” called a class. It is also a mechanism for restricting direct access to some of an object’s components (data hiding).

ব্যাখ্যা: এনক্যাপসুলেশন হল ডেটা (অ্যাট্রিবিউট) এবং সেই ডেটার উপর কাজ করা মেথডগুলিকে একটি একক ইউনিটে, বা “ক্যাপসুল”-এ আবদ্ধ করা, যাকে ক্লাস বলা হয়। এটি একটি অবজেক্টের কিছু উপাদানে সরাসরি অ্যাক্সেস সীমাবদ্ধ করার একটি প্রক্রিয়াও বটে (ডেটা হাইডিং)।

Inheritance and Polymorphism

61. The ability of an object to take on many forms is known as…
একটি অবজেক্টের একাধিক রূপ ধারণ করার ক্ষমতাকে কী বলা হয়?

  • A) Inheritance
  • B) Encapsulation
  • C) Polymorphism
  • D) Abstraction

Correct Answer: C) Polymorphism

Explanation: Polymorphism (from Greek, meaning “many forms”) allows a single interface (like a function name or operator) to be used for different underlying forms (data types). Examples include function overloading and operator overloading (compile-time polymorphism) and virtual functions (run-time polymorphism).

ব্যাখ্যা: পলিমরফিজম (গ্রীক থেকে, যার অর্থ “বহুরূপ”) একটি একক ইন্টারফেসকে (যেমন একটি ফাংশনের নাম বা অপারেটর) বিভিন্ন অন্তর্নিহিত ফর্মের (ডেটা টাইপ) জন্য ব্যবহার করার অনুমতি দেয়। উদাহরণগুলির মধ্যে রয়েছে ফাংশন ওভারলোডিং এবং অপারেটর ওভারলোডিং (কম্পাইল-টাইম পলিমরফিজম) এবং ভার্চুয়াল ফাংশন (রান-টাইম পলিমরফিজম)।

62. When a class derives properties from more than one base class, it is called…
যখন একটি ক্লাস একাধিক বেস ক্লাস থেকে বৈশিষ্ট্য অর্জন করে, তখন তাকে কী বলা হয়?

  • A) Single Inheritance
  • B) Multilevel Inheritance
  • C) Multiple Inheritance
  • D) Hierarchical Inheritance

Correct Answer: C) Multiple Inheritance

Explanation: Multiple inheritance is a feature of some object-oriented languages (like C++) where a class can inherit members from more than one superclass (base class).

ব্যাখ্যা: মাল্টিপল ইনহেরিটেন্স কিছু অবজেক্ট-ওরিয়েন্টেড ভাষার (যেমন C++) একটি বৈশিষ্ট্য যেখানে একটি ক্লাস একাধিক সুপারক্লাস (বেস ক্লাস) থেকে সদস্য ইনহেরিট করতে পারে।

63. What is function overloading an example of?
ফাংশন ওভারলোডিং কিসের উদাহরণ?

  • A) Run-time polymorphism
  • B) Compile-time polymorphism
  • C) Inheritance
  • D) Data hiding

Correct Answer: B) Compile-time polymorphism

Explanation: Function overloading is a form of compile-time (or static) polymorphism. The compiler determines which version of the function to call at compile time based on the number and type of arguments passed to it.

ব্যাখ্যা: ফাংশন ওভারলোডিং কম্পাইল-টাইম (বা স্ট্যাটিক) পলিমরফিজমের একটি রূপ। কম্পাইলার কম্পাইল করার সময় নির্ধারণ করে যে ফাংশনের কোন সংস্করণটি কল করতে হবে, যা তাকে পাস করা আর্গুমেন্টের সংখ্যা এবং টাইপের উপর ভিত্তি করে নির্ধারিত হয়।

64. In inheritance, the class that is being inherited from is called the…
ইনহেরিটেন্সে, যে ক্লাস থেকে ইনহেরিট করা হয় তাকে কী বলা হয়?

  • A) Subclass or Derived class
  • B) Superclass or Base class
  • C) Friend class
  • D) Child class

Correct Answer: B) Superclass or Base class

Explanation: The class whose properties are inherited by another class is known as the Base Class or Superclass. The class that inherits the properties is known as the Derived Class or Subclass.

ব্যাখ্যা: যে ক্লাসের বৈশিষ্ট্যগুলি অন্য ক্লাস দ্বারা ইনহেরিট করা হয় তাকে বেস ক্লাস বা সুপারক্লাস বলা হয়। যে ক্লাস বৈশিষ্ট্যগুলি ইনহেরিট করে তাকে ডিরাইভড ক্লাস বা সাবক্লাস বলা হয়।

65. Run-time polymorphism in C++ is achieved through…
C++-এ রান-টাইম পলিমরফিজম কিসের মাধ্যমে অর্জন করা হয়?

  • A) Function Overloading
  • B) Operator Overloading
  • C) Templates
  • D) Virtual Functions

Correct Answer: D) Virtual Functions

Explanation: Run-time polymorphism (or dynamic binding) is achieved in C++ using virtual functions and pointers/references to base classes. This allows the decision of which function to call to be deferred until runtime, based on the actual type of the object being pointed to.

ব্যাখ্যা: C++-এ রান-টাইম পলিমরফিজম (বা ডাইনামিক বাইন্ডিং) ভার্চুয়াল ফাংশন এবং বেস ক্লাসের পয়েন্টার/রেফারেন্স ব্যবহার করে অর্জন করা হয়। এটি কোন ফাংশনটি কল করতে হবে সেই সিদ্ধান্তটি রানটাইম পর্যন্ত স্থগিত রাখতে দেয়, যা নির্দেশিত অবজেক্টের আসল টাইপের উপর ভিত্তি করে নির্ধারিত হয়।

C++ as an OO Language

66. Which keyword is used to define a class in C++?
C++ এ একটি ক্লাস সংজ্ঞায়িত করতে কোন কীওয়ার্ড ব্যবহার করা হয়?

  • A) `struct`
  • B) `object`
  • C) `class`
  • D) `blueprint`

Correct Answer: C) `class`

Explanation: The `class` keyword is used to declare a class in C++, followed by the class name. While `struct` can also be used, its members are public by default, whereas in `class`, members are private by default.

ব্যাখ্যা: `class` কীওয়ার্ডটি C++ এ একটি ক্লাস ঘোষণা করতে ব্যবহৃত হয়, তারপরে ক্লাসের নাম থাকে। যদিও `struct` ও ব্যবহার করা যেতে পারে, তবে এর সদস্যরা ডিফল্টরূপে পাবলিক থাকে, যেখানে `class`-এ সদস্যরা ডিফল্টরূপে প্রাইভেট থাকে।

67. In a C++ class, what is the default access specifier for members?
একটি C++ ক্লাসে, সদস্যদের জন্য ডিফল্ট অ্যাক্সেস স্পেসিফায়ার কী?

  • A) `public`
  • B) `private`
  • C) `protected`
  • D) `friend`

Correct Answer: B) `private`

Explanation: If no access specifier is mentioned for the members of a class, they are `private` by default. This is a key difference from a `struct`, where members are `public` by default.

ব্যাখ্যা: যদি একটি ক্লাসের সদস্যদের জন্য কোনো অ্যাক্সেস স্পেসিফায়ার উল্লেখ না করা হয়, তবে তারা ডিফল্টরূপে `private` থাকে। এটি `struct` থেকে একটি মূল পার্থক্য, যেখানে সদস্যরা ডিফল্টরূপে `public` থাকে।

68. What is a constructor in C++?
C++ এ কনস্ট্রাক্টর কী?

  • A) A function that is called to destroy an object.
  • B) A member function with the same name as its class, used to initialize objects.
  • C) A function to copy an object.
  • D) A global function to create objects.

Correct Answer: B) A member function with the same name as its class, used to initialize objects.

Explanation: A constructor is a special member function that is automatically called when an object of a class is created. Its primary job is to initialize the data members of the new object. It has the same name as the class and does not have a return type.

ব্যাখ্যা: কনস্ট্রাক্টর একটি বিশেষ মেম্বার ফাংশন যা একটি ক্লাসের অবজেক্ট তৈরি করার সময় স্বয়ংক্রিয়ভাবে কল হয়। এর প্রধান কাজ হল নতুন অবজেক্টের ডেটা মেম্বারদের ইনিশিয়ালাইজ করা। এর নাম ক্লাসের নামের মতোই হয় এবং এর কোনো রিটার্ন টাইপ থাকে না।

69. Which operator is used in C++ to define the scope of a function outside its class?
C++ এ একটি ফাংশনকে তার ক্লাসের বাইরে সংজ্ঞায়িত করতে কোন অপারেটর ব্যবহার করা হয়?

  • A) `.` (dot)
  • B) `->` (arrow)
  • C) `::` (Scope Resolution Operator)
  • D) `:` (colon)

Correct Answer: C) `::` (Scope Resolution Operator)

Explanation: The Scope Resolution Operator `::` is used to define a member function outside the class definition. The syntax is `return_type ClassName::functionName(parameters) { … }`.

ব্যাখ্যা: স্কোপ রেজোলিউশন অপারেটর `::` একটি মেম্বার ফাংশনকে ক্লাস ডেফিনিশনের বাইরে সংজ্ঞায়িত করতে ব্যবহৃত হয়। সিনট্যাক্সটি হল `return_type ClassName::functionName(parameters) { … }`।

70. What is a Destructor in C++?
C++ এ ডেস্ট্রাক্টর কী?

  • A) A function to build an object.
  • B) A member function that is automatically called when an object goes out of scope or is deleted.
  • C) A function to overload operators.
  • D) A function to inherit properties.

Correct Answer: B) A member function that is automatically called when an object goes out of scope or is deleted.

Explanation: A destructor is a special member function used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed. Its name is the class name preceded by a tilde (`~`) and it takes no arguments and has no return value.

ব্যাখ্যা: ডেস্ট্রাক্টর একটি বিশেষ মেম্বার ফাংশন যা একটি অবজেক্ট ধ্বংস হওয়ার সময় মেমরি ডিঅ্যালোকেট করতে এবং অন্যান্য ক্লিনআপের কাজ করতে ব্যবহৃত হয়। এর নাম হল ক্লাসের নামের আগে একটি টিল্ড (`~`) চিহ্ন এবং এটি কোনো আর্গুমেন্ট নেয় না এবং এর কোনো রিটার্ন ভ্যালু নেই।

71. Which of these is NOT a pillar of OOP?
এর মধ্যে কোনটি OOP-এর স্তম্ভ নয়?

  • A) Polymorphism
  • B) Abstraction
  • C) Compilation
  • D) Encapsulation

Correct Answer: C) Compilation

Explanation: The four main pillars of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism. Compilation is the process of converting source code into machine code, which is a general programming concept, not an OOP-specific pillar.

ব্যাখ্যা: OOP-এর চারটি প্রধান স্তম্ভ হল অ্যাবস্ট্রাকশন, এনক্যাপসুলেশন, ইনহেরিটেন্স, এবং পলিমরফিজম। কম্পাইলেশন হল সোর্স কোডকে মেশিন কোডে রূপান্তর করার প্রক্রিয়া, যা একটি সাধারণ প্রোগ্রামিং ধারণা, OOP-নির্দিষ্ট কোনো স্তম্ভ নয়।

72. Which concept allows a new class to use the properties of an existing class?
কোন ধারণাটি একটি নতুন ক্লাসকে একটি বিদ্যমান ক্লাসের বৈশিষ্ট্য ব্যবহার করার অনুমতি দেয়?

  • A) Polymorphism
  • B) Inheritance
  • C) Abstraction
  • D) Encapsulation

Correct Answer: B) Inheritance

Explanation: Inheritance is the mechanism by which one class (the derived class) acquires the properties (methods and fields) of another class (the base class). It promotes code reusability.

ব্যাখ্যা: ইনহেরিটেন্স হল সেই প্রক্রিয়া যার মাধ্যমে একটি ক্লাস (ডিরাইভড ক্লাস) অন্য একটি ক্লাসের (বেস ক্লাস) বৈশিষ্ট্য (মেথড এবং ফিল্ড) অর্জন করে। এটি কোডের পুনঃব্যবহারযোগ্যতা বৃদ্ধি করে।

73. C++ was developed by…
C++ কে ডেভেলপ করেছেন?

  • A) Dennis Ritchie
  • B) Bjarne Stroustrup
  • C) James Gosling
  • D) Guido van Rossum

Correct Answer: B) Bjarne Stroustrup

Explanation: Bjarne Stroustrup developed C++ at Bell Labs, starting in 1979, as an extension of the C language. Dennis Ritchie created C, James Gosling created Java, and Guido van Rossum created Python.

ব্যাখ্যা: Bjarne Stroustrup বেল ল্যাবসে 1979 সাল থেকে C++ তৈরি করেন, যা C ভাষার একটি এক্সটেনশন হিসাবে শুরু হয়েছিল। ডেনিস রিচি C তৈরি করেন, জেমস গসলিং জাভা তৈরি করেন, এবং গুইডো ভ্যান রসম পাইথন তৈরি করেন।

74. The `protected` access specifier in C++ makes a class member accessible to…
C++-এ `protected` অ্যাক্সেস স্পেসিফায়ার একটি ক্লাস সদস্যকে কাদের কাছে অ্যাক্সেসযোগ্য করে তোলে?

  • A) Only the same class.
  • B) The same class and its friend classes.
  • C) The same class and its derived classes.
  • D) Any function in the program.

Correct Answer: C) The same class and its derived classes.

Explanation: A `protected` member is accessible within its own class and by any class derived from it (subclasses). It cannot be accessed by non-member, non-friend functions from outside.

ব্যাখ্যা: একটি `protected` সদস্য তার নিজের ক্লাসের মধ্যে এবং তার থেকে ডিরাইভ করা যেকোনো ক্লাস (সাবক্লাস) দ্বারা অ্যাক্সেসযোগ্য। এটি বাইরে থেকে নন-মেম্বার, নন-ফ্রেন্ড ফাংশন দ্বারা অ্যাক্সেস করা যায় না।

75. Which of the following operators cannot be overloaded in C++?
নিচের কোন অপারেটরটি C++ এ ওভারলোড করা যায় না?

  • A) `+`
  • B) `()`
  • C) `::`
  • D) `[]`

Correct Answer: C) `::`

Explanation: Most operators in C++ can be overloaded. However, a few cannot be, including the scope resolution operator (`::`), member access operator (`.`), pointer-to-member operator (`.*`), and the conditional operator (`?:`).

ব্যাখ্যা: C++-এর বেশিরভাগ অপারেটর ওভারলোড করা যায়। তবে, কিছু অপারেটর করা যায় না, যার মধ্যে রয়েছে স্কোপ রেজোলিউশন অপারেটর (`::`), মেম্বার অ্যাক্সেস অপারেটর (`.`), পয়েন্টার-টু-মেম্বার অপারেটর (`.*`), এবং কন্ডিশনাল অপারেটর (`?:`)।

76. What is the result of data hiding?
ডেটা হাইডিং এর ফলাফল কী?

  • A) Increased data security and robustness.
  • B) Slower program execution.
  • C) More complex code.
  • D) Decreased code reusability.

Correct Answer: A) Increased data security and robustness.

Explanation: Data hiding, a part of encapsulation, restricts access to an object’s internal data. This prevents accidental or unauthorized modification, leading to more secure, robust, and maintainable code.

ব্যাখ্যা: ডেটা হাইডিং, যা এনক্যাপসুলেশনের একটি অংশ, একটি অবজেক্টের অভ্যন্তরীণ ডেটাতে অ্যাক্সেস সীমাবদ্ধ করে। এটি আকস্মিক বা অননুমোদিত পরিবর্তন প্রতিরোধ করে, যা আরও সুরক্ষিত, শক্তিশালী এবং রক্ষণাবেক্ষণযোগ্য কোডের দিকে নিয়ে যায়।

77. In C++, `cin` is a(n)…
C++ এ, `cin` হল একটি…

  • A) Function
  • B) Object
  • C) Keyword
  • D) Class

Correct Answer: B) Object

Explanation: `cin` is an object of the `istream` class. It is used for standard input, typically from the keyboard, using the extraction operator `>>`.

ব্যাখ্যা: `cin` হল `istream` ক্লাসের একটি অবজেক্ট। এটি স্ট্যান্ডার্ড ইনপুটের জন্য ব্যবহৃত হয়, সাধারণত কীবোর্ড থেকে, এক্সট্র্যাকশন অপারেটর `>>` ব্যবহার করে।

78. A class where all member functions are `pure virtual` is known as a(n)…
একটি ক্লাস যেখানে সমস্ত মেম্বার ফাংশন `pure virtual` হয়, তাকে কী বলা হয়?

  • A) Friend Class
  • B) Abstract Class
  • C) Virtual Class
  • D) Static Class

Correct Answer: B) Abstract Class

Explanation: A class that has at least one pure virtual function (`= 0`) is an abstract class. You cannot create an instance (object) of an abstract class. It is meant to be used as a base class from which other classes can inherit.

ব্যাখ্যা: যে ক্লাসে কমপক্ষে একটি পিওর ভার্চুয়াল ফাংশন (`= 0`) থাকে, সেটি একটি অ্যাবস্ট্রাক্ট ক্লাস। আপনি একটি অ্যাবস্ট্রাক্ট ক্লাসের ইনস্ট্যান্স (অবজেক্ট) তৈরি করতে পারবেন না। এটি একটি বেস ক্লাস হিসাবে ব্যবহৃত হওয়ার জন্য তৈরি, যেখান থেকে অন্য ক্লাস ইনহেরিট করতে পারে।

79. Which header file should be included to use `cout` and `cin`?
`cout` এবং `cin` ব্যবহার করার জন্য কোন হেডার ফাইল অন্তর্ভুক্ত করা উচিত?

  • A) ``
  • B) ``
  • C) ``
  • D) ``

Correct Answer: C) ``

Explanation: The `` header file contains the declarations for the standard input/output stream objects like `cin`, `cout`, `cerr`, etc.

ব্যাখ্যা: `` হেডার ফাইলে `cin`, `cout`, `cerr` ইত্যাদির মতো স্ট্যান্ডার্ড ইনপুট/আউটপুট স্ট্রিম অবজেক্টের ডিক্লারেশন থাকে।

80. How do you achieve “has-a” relationship between classes?
ক্লাসগুলির মধ্যে “has-a” সম্পর্ক কীভাবে অর্জন করা হয়?

  • A) Inheritance
  • B) Polymorphism
  • C) Abstraction
  • D) Composition (Object Containment)

Correct Answer: D) Composition (Object Containment)

Explanation: A “has-a” relationship is modeled using composition, where one class contains an object of another class as a member variable. For example, a `Car` class “has-a” `Engine` object. Inheritance models an “is-a” relationship (e.g., a `Car` “is-a” `Vehicle`).

ব্যাখ্যা: একটি “has-a” সম্পর্ক কম্পোজিশন ব্যবহার করে মডেল করা হয়, যেখানে একটি ক্লাস অন্য ক্লাসের একটি অবজেক্টকে মেম্বার ভেরিয়েবল হিসাবে ধারণ করে। উদাহরণস্বরূপ, একটি `Car` ক্লাসের একটি `Engine` অবজেক্ট “আছে”। ইনহেরিটেন্স একটি “is-a” সম্পর্ক মডেল করে (যেমন, একটি `Car` হল একটি `Vehicle`)।

Mixed Topics (C & OOP)

81. What is the output of `printf(“%d”, ‘B’ – ‘A’);`?
`printf(“%d”, ‘B’ – ‘A’);` এর আউটপুট কী?

  • A) 1
  • B) 2
  • C) ‘B’
  • D) Error

Correct Answer: A) 1

Explanation: In C, characters are represented by their ASCII values. The ASCII value of ‘A’ is 65 and ‘B’ is 66. So, the expression `’B’ – ‘A’` evaluates to `66 – 65`, which is `1`.

ব্যাখ্যা: C-তে, অক্ষরগুলি তাদের ASCII মান দ্বারা উপস্থাপিত হয়। ‘A’-এর ASCII মান 65 এবং ‘B’-এর 66। সুতরাং, `’B’ – ‘A’` এক্সপ্রেশনটি `66 – 65` হিসাবে গণনা করা হয়, যা `1`।

82. A `while(1)` loop is an…
একটি `while(1)` লুপ হল একটি…

  • A) Invalid loop
  • B) Loop that runs once
  • C) Infinite loop
  • D) Loop that never runs

Correct Answer: C) Infinite loop

Explanation: In C, any non-zero value is treated as `true` in a boolean context. Since `1` is non-zero, the condition `while(1)` is always true, leading to an infinite loop unless terminated by a `break`, `return`, or `exit()` inside the loop.

ব্যাখ্যা: C-তে, যেকোনো নন-জিরো মান বুলিয়ান প্রসঙ্গে `true` হিসাবে গণ্য হয়। যেহেতু `1` একটি নন-জিরো মান, তাই `while(1)` শর্তটি সর্বদা সত্য থাকে, যা একটি অসীম লুপের দিকে নিয়ে যায়, যদি না লুপের ভিতরে `break`, `return`, বা `exit()` দ্বারা এটি বন্ধ করা হয়।

83. The `this` pointer in C++ holds the address of…
C++ এ `this` পয়েন্টার কিসের অ্যাড্রেস ধারণ করে?

  • A) The base class object.
  • B) The current object for which a member function is called.
  • C) The next object in memory.
  • D) The friend class object.

Correct Answer: B) The current object for which a member function is called.

Explanation: The `this` pointer is an implicit pointer available to all non-static member functions of a class. It points to the specific object on which the member function was invoked.

ব্যাখ্যা: `this` পয়েন্টার একটি ক্লাসের সমস্ত নন-স্ট্যাটিক মেম্বার ফাংশনের জন্য উপলব্ধ একটি অন্তর্নিহিত পয়েন্টার। এটি সেই নির্দিষ্ট অবজেক্টকে নির্দেশ করে যার উপর মেম্বার ফাংশনটি কল করা হয়েছে।

84. Which function is used to find the length of a C-style string?
একটি C-স্টাইল স্ট্রিংয়ের দৈর্ঘ্য খুঁজে পেতে কোন ফাংশন ব্যবহার করা হয়?

  • A) `str_len()`
  • B) `len()`
  • C) `strlen()`
  • D) `sizeof()`

Correct Answer: C) `strlen()`

Explanation: The `strlen()` function from the `` library calculates the length of a string, which is the number of characters before the null terminator (`\0`). `sizeof()` would give the total allocated memory size, which is different.

ব্যাখ্যা: `` লাইব্রেরির `strlen()` ফাংশন একটি স্ট্রিংয়ের দৈর্ঘ্য গণনা করে, যা নাল টার্মিনেটরের (`\0`) আগের অক্ষরের সংখ্যা। `sizeof()` মোট বরাদ্দকৃত মেমরির আকার দেবে, যা ভিন্ন।

85. C++ is a superset of which language?
C++ কোন ভাষার একটি সুপারসেট?

  • A) Java
  • B) C
  • C) Python
  • D) Pascal

Correct Answer: B) C

Explanation: C++ was designed to be a “better C,” extending the C language with object-oriented features like classes, inheritance, etc. Most valid C programs are also valid C++ programs.

ব্যাখ্যা: C++ কে “একটি উন্নত C” হিসাবে ডিজাইন করা হয়েছিল, যা C ভাষাকে ক্লাস, ইনহেরিটেন্স ইত্যাদির মতো অবজেক্ট-ওরিয়েন্টেড বৈশিষ্ট্য দিয়ে প্রসারিত করে। বেশিরভাগ বৈধ C প্রোগ্রামই বৈধ C++ প্রোগ্রাম।

86. What is a file pointer in C?
C-তে ফাইল পয়েন্টার কী?

  • A) A pointer to the file name.
  • B) A pointer to a `FILE` structure that holds information about the file.
  • C) An integer representing the file’s position.
  • D) A pointer to the last character of a file.

Correct Answer: B) A pointer to a `FILE` structure that holds information about the file.

Explanation: In C, a file pointer is a pointer to a structure of type `FILE`. This structure, defined in ``, contains all the necessary information to manage the file stream, such as its current position, error indicators, and a buffer.

ব্যাখ্যা: C-তে, একটি ফাইল পয়েন্টার হল `FILE` টাইপের একটি স্ট্রাকচারের পয়েন্টার। এই স্ট্রাকচারটি, যা ``-এ সংজ্ঞায়িত, ফাইল স্ট্রিম পরিচালনা করার জন্য সমস্ত প্রয়োজনীয় তথ্য ধারণ করে, যেমন এর বর্তমান অবস্থান, ত্রুটি নির্দেশক, এবং একটি বাফার।

87. What is the use of the `new` operator in C++?
C++-এ `new` অপারেটরের ব্যবহার কী?

  • A) To create a new file.
  • B) To declare a new variable.
  • C) To allocate memory dynamically on the heap.
  • D) To create a new namespace.

Correct Answer: C) To allocate memory dynamically on the heap.

Explanation: The `new` operator in C++ is used for dynamic memory allocation. It allocates memory from the free store (heap) and returns a pointer of the appropriate type to the allocated memory. It is the C++ equivalent of `malloc` but also calls the constructor for objects.

ব্যাখ্যা: C++-এ `new` অপারেটরটি ডাইনামিক মেমরি অ্যালোকেশনের জন্য ব্যবহৃত হয়। এটি ফ্রী স্টোর (হিপ) থেকে মেমরি বরাদ্দ করে এবং বরাদ্দকৃত মেমরির জন্য উপযুক্ত টাইপের একটি পয়েন্টার রিটার্ন করে। এটি `malloc`-এর C++ সমতুল্য, তবে এটি অবজেক্টের জন্য কনস্ট্রাক্টরও কল করে।

88. In C, if you pass an array to a function, what is actually passed?
C-তে, যদি আপনি একটি অ্যারে একটি ফাংশনে পাস করেন, তবে আসলে কী পাস হয়?

  • A) The entire array is copied.
  • B) The address of the first element of the array.
  • C) The size of the array.
  • D) The last element of the array.

Correct Answer: B) The address of the first element of the array.

Explanation: C always uses pass-by-value. When an array name is passed to a function, it “decays” into a pointer to its first element. So, the address of the first element is passed by value. The function can then use this address to modify the original array’s contents.

ব্যাখ্যা: C সর্বদা পাস-বাই-ভ্যালু ব্যবহার করে। যখন একটি অ্যারের নাম একটি ফাংশনে পাস করা হয়, তখন এটি তার প্রথম উপাদানের একটি পয়েন্টারে “ডেকে” (রূপান্তরিত) হয়। সুতরাং, প্রথম উপাদানের অ্যাড্রেসটি ভ্যালু হিসাবে পাস করা হয়। ফাংশনটি তারপর এই অ্যাড্রেস ব্যবহার করে মূল অ্যারের বিষয়বস্তু পরিবর্তন করতে পারে।

89. What does a pure virtual function signify?
একটি পিওর ভার্চুয়াল ফাংশন কী বোঝায়?

  • A) A function that must not be overridden.
  • B) A function that has no body and must be implemented by derived classes.
  • C) A function that can only be called from a base class.
  • D) A function that returns a null pointer.

Correct Answer: B) A function that has no body and must be implemented by derived classes.

Explanation: A pure virtual function (e.g., `virtual void draw() = 0;`) is a virtual function for which we don’t have an implementation. It serves as a placeholder, forcing any concrete (non-abstract) derived class to provide its own implementation.

ব্যাখ্যা: একটি পিওর ভার্চুয়াল ফাংশন (যেমন, `virtual void draw() = 0;`) একটি ভার্চুয়াল ফাংশন যার কোনো বাস্তবায়ন থাকে না। এটি একটি স্থানধারক হিসাবে কাজ করে, যা যেকোনো কংক্রিট (নন-অ্যাবস্ট্রাক্ট) ডিরাইভড ক্লাসকে তার নিজস্ব বাস্তবায়ন প্রদান করতে বাধ্য করে।

90. Which bitwise operator is suitable for checking if a particular bit is set?
একটি নির্দিষ্ট বিট সেট করা আছে কিনা তা পরীক্ষা করার জন্য কোন বিটওয়াইজ অপারেটর উপযুক্ত?

  • A) `|` (Bitwise OR)
  • B) `^` (Bitwise XOR)
  • C) `~` (Bitwise NOT)
  • D) `&` (Bitwise AND)

Correct Answer: D) `&` (Bitwise AND)

Explanation: To check if the nth bit is set in a number, you can perform a bitwise AND with a mask that has only the nth bit set (e.g., `1 << n`). If the result is non-zero, the bit was set. For example, `(number & 8)` checks if the 4th bit (value 8) is set.

ব্যাখ্যা: একটি সংখ্যায় n-তম বিট সেট করা আছে কিনা তা পরীক্ষা করতে, আপনি একটি মাস্কের সাথে একটি বিটওয়াইজ AND করতে পারেন যেখানে শুধুমাত্র n-তম বিটটি সেট করা আছে (যেমন, `1 << n`)। যদি ফলাফলটি নন-জিরো হয়, তবে বিটটি সেট করা ছিল। উদাহরণস্বরূপ, `(number & 8)` চতুর্থ বিটটি (মান 8) সেট করা আছে কিনা তা পরীক্ষা করে।

91. What is the difference between `struct` in C and `struct` in C++?
C-এর `struct` এবং C++-এর `struct`-এর মধ্যে পার্থক্য কী?

  • A) There is no difference.
  • B) C++ structs can have member functions, while C structs cannot.
  • C) C structs have private members by default.
  • D) C++ structs cannot have data members.

Correct Answer: B) C++ structs can have member functions, while C structs cannot.

Explanation: The main difference is that a `struct` in C++ is almost identical to a `class`, capable of having member functions, constructors, inheritance, etc. The only difference is default access: `struct` members are public by default, `class` members are private. A `struct` in C can only contain data members.

ব্যাখ্যা: প্রধান পার্থক্য হল C++-এ একটি `struct` প্রায় একটি `class`-এর মতোই, যা মেম্বার ফাংশন, কনস্ট্রাক্টর, ইনহেরিটেন্স ইত্যাদি ধারণ করতে পারে। একমাত্র পার্থক্য হল ডিফল্ট অ্যাক্সেস: `struct`-এর সদস্যরা ডিফল্টরূপে পাবলিক, `class`-এর সদস্যরা প্রাইভেট। C-এর একটি `struct` শুধুমাত্র ডেটা মেম্বার ধারণ করতে পারে।

92. The `delete` operator in C++ should be used for memory allocated with…
C++-এ `delete` অপারেটরটি কিসের সাথে বরাদ্দ করা মেমরির জন্য ব্যবহার করা উচিত?

  • A) `malloc()`
  • B) `calloc()`
  • C) `new`
  • D) `auto` variables

Correct Answer: C) `new`

Explanation: `new` and `delete` (and `new[]`/`delete[]`) are a pair. Memory allocated with `new` must be deallocated with `delete`. Memory allocated with `malloc`/`calloc` must be deallocated with `free()`. Mixing them leads to undefined behavior.

ব্যাখ্যা: `new` এবং `delete` (এবং `new[]`/`delete[]`) একটি জোড়া। `new` দিয়ে বরাদ্দ করা মেমরি অবশ্যই `delete` দিয়ে ডিঅ্যালোকেট করতে হবে। `malloc`/`calloc` দিয়ে বরাদ্দ করা মেমরি অবশ্যই `free()` দিয়ে ডিঅ্যালোকেট করতে হবে। এগুলিকে মিশ্রিত করলে আনডিফাইন্ড বিহেভিয়ার হয়।

93. Which of the following is true about a static member function in C++?
C++-এ একটি স্ট্যাটিক মেম্বার ফাংশন সম্পর্কে নিচের কোনটি সত্য?

  • A) It can access all member variables of the class.
  • B) It can only be called through an object of the class.
  • C) It can be called without creating an object of the class.
  • D) It cannot be defined outside the class.

Correct Answer: C) It can be called without creating an object of the class.

Explanation: A static member function belongs to the class rather than to any specific object. Therefore, it can be called using the class name and the scope resolution operator (e.g., `ClassName::static_func();`). It does not have a `this` pointer and can only access static member variables.

ব্যাখ্যা: একটি স্ট্যাটিক মেম্বার ফাংশন কোনো নির্দিষ্ট অবজেক্টের পরিবর্তে ক্লাসের অন্তর্গত। অতএব, এটি ক্লাসের নাম এবং স্কোপ রেজোলিউশন অপারেটর ব্যবহার করে কল করা যেতে পারে (যেমন, `ClassName::static_func();`)। এটির কোনো `this` পয়েন্টার নেই এবং এটি শুধুমাত্র স্ট্যাটিক মেম্বার ভেরিয়েবল অ্যাক্সেস করতে পারে।

94. What does `fflush(stdin)` do?
`fflush(stdin)` কী কাজ করে?

  • A) Flushes the output buffer (`stdout`).
  • B) Flushes the input buffer (`stdin`).
  • C) It’s a standard and portable way to clear the input buffer.
  • D) It’s behavior is undefined for input streams.

Correct Answer: D) It’s behavior is undefined for input streams.

Explanation: According to the C standard, `fflush()` is only defined for output streams (like `stdout`) and update streams. Applying it to an input stream (`stdin`) results in undefined behavior. While some compilers might implement it to clear the input buffer, it is not portable and should be avoided.

ব্যাখ্যা: C স্ট্যান্ডার্ড অনুসারে, `fflush()` শুধুমাত্র আউটপুট স্ট্রিম (যেমন `stdout`) এবং আপডেট স্ট্রিমের জন্য সংজ্ঞায়িত। এটিকে একটি ইনপুট স্ট্রিমে (`stdin`) প্রয়োগ করলে আনডিফাইন্ড বিহেভিয়ার হয়। যদিও কিছু কম্পাইলার ইনপুট বাফার পরিষ্কার করার জন্য এটি বাস্তবায়ন করতে পারে, তবে এটি পোর্টেবল নয় এবং এড়িয়ে চলা উচিত।

95. A copy constructor is a constructor which…
একটি কপি কনস্ট্রাক্টর হল একটি কনস্ট্রাক্টর যা…

  • A) Creates a copy of the class definition.
  • B) Creates a new object as a copy of an existing object.
  • C) Copies one function to another.
  • D) Has at least two arguments.

Correct Answer: B) Creates a new object as a copy of an existing object.

Explanation: A copy constructor is a special constructor in C++ that is called when a new object is created from an existing object, as a copy. It typically takes a single argument: a const reference to an object of the same class.

ব্যাখ্যা: একটি কপি কনস্ট্রাক্টর C++-এ একটি বিশেষ কনস্ট্রাক্টর যা কল করা হয় যখন একটি নতুন অবজেক্ট একটি বিদ্যমান অবজেক্টের কপি হিসাবে তৈরি করা হয়। এটি সাধারণত একটি একক আর্গুমেন্ট নেয়: একই ক্লাসের একটি অবজেক্টের একটি const রেফারেন্স।

96. The `goto` statement is generally avoided because…
`goto` স্টেটমেন্ট সাধারণত এড়ানো হয় কারণ…

  • A) It is not a C keyword.
  • B) It makes program logic difficult to follow (spaghetti code).
  • C) It is very slow.
  • D) It can only jump forward, not backward.

Correct Answer: B) It makes program logic difficult to follow (spaghetti code).

Explanation: The `goto` statement allows for unconditional jumps to a labeled statement anywhere in the function. Its overuse can lead to “spaghetti code,” which is unstructured and very difficult to read, understand, and maintain. Structured control flow (if, for, while) is highly preferred.

ব্যাখ্যা: `goto` স্টেটমেন্টটি ফাংশনের যেকোনো স্থানে একটি লেবেলযুক্ত স্টেটমেন্টে শর্তহীন জাম্পের অনুমতি দেয়। এর অতিরিক্ত ব্যবহার “স্প্যাগেটি কোড” তৈরি করতে পারে, যা অসংগঠিত এবং পড়া, বোঝা এবং রক্ষণাবেক্ষণ করা খুব কঠিন। স্ট্রাকচার্ড কন্ট্রোল ফ্লো (if, for, while) বেশি পছন্দের।

97. How is an “is-a” relationship represented in OOP?
OOP-তে “is-a” সম্পর্ক কীভাবে উপস্থাপন করা হয়?

  • A) Composition
  • B) Aggregation
  • C) Friendship
  • D) Inheritance

Correct Answer: D) Inheritance

Explanation: The “is-a” relationship signifies specialization. For example, a `Dog` is a type of `Animal`. This is modeled in OOP using public inheritance, where the `Dog` class would inherit from the `Animal` class.

ব্যাখ্যা: “is-a” সম্পর্কটি বিশেষীকরণ বোঝায়। উদাহরণস্বরূপ, একটি `Dog` হল এক ধরণের `Animal`। এটি OOP-তে পাবলিক ইনহেরিটেন্স ব্যবহার করে মডেল করা হয়, যেখানে `Dog` ক্লাসটি `Animal` ক্লাস থেকে ইনহেরিট করবে।

98. Which of the following correctly declares a pointer to a function that takes an `int` and returns an `int`?
নিচের কোনটি সঠিকভাবে একটি ফাংশন পয়েন্টার ঘোষণা করে যা একটি `int` নেয় এবং একটি `int` রিটার্ন করে?

  • A) `int *ptr(int);`
  • B) `int (*ptr)(int);`
  • C) `int ptr*(int);`
  • D) `*ptr(int);`

Correct Answer: B) `int (*ptr)(int);`

Explanation: The parentheses around `*ptr` are crucial. They specify that `ptr` is a pointer. Without them, `int *ptr(int);` would declare a function named `ptr` that takes an `int` and returns a pointer to an `int` (`int*`).

ব্যাখ্যা: `*ptr`-এর চারপাশে বন্ধনীগুলি অত্যন্ত গুরুত্বপূর্ণ। এগুলি নির্দিষ্ট করে যে `ptr` একটি পয়েন্টার। সেগুলি ছাড়া, `int *ptr(int);` `ptr` নামের একটি ফাংশন ঘোষণা করবে যা একটি `int` নেয় এবং একটি `int` (`int*`) এর পয়েন্টার রিটার্ন করে।

99. Which C++ feature allows a function or class to work with different data types without being rewritten?
কোন C++ বৈশিষ্ট্য একটি ফাংশন বা ক্লাসকে পুনরায় লেখা ছাড়াই বিভিন্ন ডেটা টাইপের সাথে কাজ করার অনুমতি দেয়?

  • A) Inheritance
  • B) Templates
  • C) Virtual Functions
  • D) Operator Overloading

Correct Answer: B) Templates

Explanation: Templates are the foundation of generic programming in C++. They allow you to write a single function or class definition that can work with any data type. The compiler generates the specific versions of the function/class for the types used at compile time.

ব্যাখ্যা: টেমপ্লেটগুলি C++-এ জেনেরিক প্রোগ্রামিংয়ের ভিত্তি। এগুলি আপনাকে একটি একক ফাংশন বা ক্লাস সংজ্ঞা লিখতে দেয় যা যেকোনো ডেটা টাইপের সাথে কাজ করতে পারে। কম্পাইলার কম্পাইল করার সময় ব্যবহৃত টাইপগুলির জন্য ফাংশন/ক্লাসের নির্দিষ্ট সংস্করণ তৈরি করে।

100. In C, the `main()` function can take arguments. What is `argv`?
C-তে, `main()` ফাংশন আর্গুমেন্ট নিতে পারে। `argv` কী?

  • A) The number of command-line arguments.
  • B) A pointer to an array of character pointers (strings) representing the command-line arguments.
  • C) The first command-line argument.
  • D) The name of the program.

Correct Answer: B) A pointer to an array of character pointers (strings) representing the command-line arguments.

Explanation: The `main` function can be declared as `int main(int argc, char *argv[])`. Here, `argc` (argument count) is an integer representing the number of command-line arguments. `argv` (argument vector) is an array of character pointers, where each pointer points to a string that is one of the command-line arguments. `argv[0]` is always the program name.

ব্যাখ্যা: `main` ফাংশনটিকে `int main(int argc, char *argv[])` হিসাবে ঘোষণা করা যেতে পারে। এখানে, `argc` (আর্গুমেন্ট কাউন্ট) একটি পূর্ণসংখ্যা যা কমান্ড-লাইন আর্গুমেন্টের সংখ্যা নির্দেশ করে। `argv` (আর্গুমেন্ট ভেক্টর) হল ক্যারেক্টার পয়েন্টারগুলির একটি অ্যারে, যেখানে প্রতিটি পয়েন্টার একটি স্ট্রিংকে নির্দেশ করে যা কমান্ড-লাইন আর্গুমেন্টগুলির মধ্যে একটি। `argv[0]` সর্বদা প্রোগ্রামের নাম হয়।

Leave a Comment

Scroll to Top