(a) C-Language
Basics, Keywords, Variables
1. Which of the following is not a valid keyword in C?
নিচের কোনটি C-তে একটি বৈধ কীওয়ার্ড নয়?
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` ডেটা টাইপের সাইজ কত?
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-তে একটি বৈধ আইডেন্টিফায়ার?
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` কীওয়ার্ড কী কাজ করে?
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 প্রোগ্রামের মৌলিক কাঠামোতে কী কী থাকে…
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` এক্সপ্রেশনটির আউটপুট কী?
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?
কোন অপারেটরটি টারনারি বা কন্ডিশনাল অপারেটর হিসাবে পরিচিত?
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++;`
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…
`==` অপারেটরটি একটি…
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-তে কোন অপারেটরের অগ্রাধিকার সর্বোচ্চ?
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-তে ফরম্যাটেড ইনপুটের জন্য কোন ফাংশন ব্যবহার করা হয়?
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);`
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?
লুপের বর্তমান ইটারেশন শেষ করে পরবর্তী ইটারেশন শুরু করার জন্য কোন স্টেটমেন্ট ব্যবহার করা হয়?
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` কেসের উদ্দেশ্য কী?
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?
কোন লুপটি অন্তত একবার কার্যকর হবেই?
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` নামের একটি এক-মাত্রিক পূর্ণসংখ্যা অ্যারে ঘোষণা করবেন?
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]` এর মান কত?
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 অ্যারের উপাদানগুলো মেমরিতে কীভাবে সংরক্ষিত হয়?
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)` কী রিটার্ন করবে?
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`) কী হিসাবে কাজ করে?
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?
একটি ভেরিয়েবলের মেমরি অ্যাড্রেস পেতে কোন অপারেটর ব্যবহার করা হয়?
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…
একটি পয়েন্টার যা কিছুকেই নির্দেশ করে না তাকে কী বলা হয়?
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);`
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?
ড্যাংলিং পয়েন্টার কী?
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++` কী করে?
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-তে একটি স্ট্রাকচার সংজ্ঞায়িত করতে কোন কীওয়ার্ড ব্যবহার করা হয়?
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`-এর মধ্যে প্রধান পার্থক্য কী?
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()` এর কোন মোড ব্যবহার করা হয়?
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`-কে কীভাবে অ্যাক্সেস করবেন?
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()` ব্যবহার করে খোলা একটি ফাইল বন্ধ করতে কোন ফাংশন ব্যবহার করা হয়?
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
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 ভেরিয়েবল কী দিয়ে শুরু হতে পারে না?
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);` এর আউটপুট কী?
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?
নিচের কোনটি একটি লজিক্যাল অপারেটর?
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?
একটি ফ্লোটিং-পয়েন্ট সংখ্যা প্রিন্ট করার জন্য ফরম্যাট স্পেসিফায়ার কী?
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` স্টেটমেন্টটি কী থেকে বের হওয়ার জন্য ব্যবহৃত হয়?
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];`-এ, এটি কতগুলো উপাদান সংরক্ষণ করতে পারে?
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));`
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*` টাইপের একটি পয়েন্টার কিসের অ্যাড্রেস ধারণ করতে পারে?
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` একটি স্ট্রাকচারের পয়েন্টার হয়, তবে এর সদস্যদের অ্যাক্সেস করতে কোন অপারেটর ব্যবহৃত হয়?
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);` কী কাজ করে?
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` এর সাইজ তার কিসের সাইজ দ্বারা নির্ধারিত হয়?
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-তে একটি বৈধ স্টোরেজ ক্লাস নয়?
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`-এর মান কী?
Correct Answer: D) A negative integer, typically -1
Explanation: `EOF` stands for End-Of-File. It is a macro defined in `
ব্যাখ্যা: `EOF` মানে End-Of-File। এটি `
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);`
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;` কী ঘোষণা করে?
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` কীওয়ার্ডটি কীসের জন্য ব্যবহৃত হয়?
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()`-এর মতো ডায়নামিক মেমরি অ্যালোকেশন ফাংশন ব্যবহার করার জন্য কোন হেডার ফাইলের প্রয়োজন?
Correct Answer: D) `
Explanation: The Standard Library header file, `
ব্যাখ্যা: স্ট্যান্ডার্ড লাইব্রেরি হেডার ফাইল, `
49. What is the purpose of the `return 0;` statement in the `main` function?
`main` ফাংশনে `return 0;` স্টেটমেন্টের উদ্দেশ্য কী?
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`?
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?
নিচের কোনটি অবজেক্ট-ওরিয়েন্টেড প্রোগ্রামিংয়ের একটি প্রাথমিক ধারণা?
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)-এর প্রধান ফোকাস কী?
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”?
কোন অ্যাপ্রোচটি সাধারণত “টপ-ডাউন”?
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?
কোন প্রোগ্রামিং প্যারাডাইম প্রসিডিউরের চেয়ে ডেটাকে বেশি গুরুত্ব দেয়?
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?
কোন প্যারাডাইমে নতুন ডেটা এবং ফাংশন যোগ করা সহজ?
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-তে ক্লাস কী?
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…
জটিল বাস্তবায়নের বিবরণ লুকিয়ে রেখে এবং একটি অবজেক্টের শুধুমাত্র প্রয়োজনীয় বৈশিষ্ট্যগুলি দেখানোর প্রক্রিয়াকে কী বলা হয়?
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)…
একটি অবজেক্ট হল একটি…
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…
একটি ক্লাসের ভিতরে সংজ্ঞায়িত ফাংশনগুলিকে কী বলা হয়?
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…
ডেটা এবং মেথডকে একটি একক ইউনিটে (একটি ক্লাস) আবদ্ধ করাকে কী বলা হয়?
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…
একটি অবজেক্টের একাধিক রূপ ধারণ করার ক্ষমতাকে কী বলা হয়?
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…
যখন একটি ক্লাস একাধিক বেস ক্লাস থেকে বৈশিষ্ট্য অর্জন করে, তখন তাকে কী বলা হয়?
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?
ফাংশন ওভারলোডিং কিসের উদাহরণ?
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…
ইনহেরিটেন্সে, যে ক্লাস থেকে ইনহেরিট করা হয় তাকে কী বলা হয়?
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++-এ রান-টাইম পলিমরফিজম কিসের মাধ্যমে অর্জন করা হয়?
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++ এ একটি ক্লাস সংজ্ঞায়িত করতে কোন কীওয়ার্ড ব্যবহার করা হয়?
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++ ক্লাসে, সদস্যদের জন্য ডিফল্ট অ্যাক্সেস স্পেসিফায়ার কী?
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++ এ কনস্ট্রাক্টর কী?
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++ এ একটি ফাংশনকে তার ক্লাসের বাইরে সংজ্ঞায়িত করতে কোন অপারেটর ব্যবহার করা হয়?
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++ এ ডেস্ট্রাক্টর কী?
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-এর স্তম্ভ নয়?
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?
কোন ধারণাটি একটি নতুন ক্লাসকে একটি বিদ্যমান ক্লাসের বৈশিষ্ট্য ব্যবহার করার অনুমতি দেয়?
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++ কে ডেভেলপ করেছেন?
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` অ্যাক্সেস স্পেসিফায়ার একটি ক্লাস সদস্যকে কাদের কাছে অ্যাক্সেসযোগ্য করে তোলে?
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++ এ ওভারলোড করা যায় না?
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?
ডেটা হাইডিং এর ফলাফল কী?
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` হল একটি…
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` হয়, তাকে কী বলা হয়?
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` ব্যবহার করার জন্য কোন হেডার ফাইল অন্তর্ভুক্ত করা উচিত?
Correct Answer: C) `
Explanation: The `
ব্যাখ্যা: `
80. How do you achieve “has-a” relationship between classes?
ক্লাসগুলির মধ্যে “has-a” সম্পর্ক কীভাবে অর্জন করা হয়?
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’);` এর আউটপুট কী?
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)` লুপ হল একটি…
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` পয়েন্টার কিসের অ্যাড্রেস ধারণ করে?
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-স্টাইল স্ট্রিংয়ের দৈর্ঘ্য খুঁজে পেতে কোন ফাংশন ব্যবহার করা হয়?
Correct Answer: C) `strlen()`
Explanation: The `strlen()` function from the `
ব্যাখ্যা: `
85. C++ is a superset of which language?
C++ কোন ভাষার একটি সুপারসেট?
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-তে ফাইল পয়েন্টার কী?
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 `
ব্যাখ্যা: C-তে, একটি ফাইল পয়েন্টার হল `FILE` টাইপের একটি স্ট্রাকচারের পয়েন্টার। এই স্ট্রাকচারটি, যা `
87. What is the use of the `new` operator in C++?
C++-এ `new` অপারেটরের ব্যবহার কী?
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-তে, যদি আপনি একটি অ্যারে একটি ফাংশনে পাস করেন, তবে আসলে কী পাস হয়?
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?
একটি পিওর ভার্চুয়াল ফাংশন কী বোঝায়?
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?
একটি নির্দিষ্ট বিট সেট করা আছে কিনা তা পরীক্ষা করার জন্য কোন বিটওয়াইজ অপারেটর উপযুক্ত?
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`-এর মধ্যে পার্থক্য কী?
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` অপারেটরটি কিসের সাথে বরাদ্দ করা মেমরির জন্য ব্যবহার করা উচিত?
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++-এ একটি স্ট্যাটিক মেম্বার ফাংশন সম্পর্কে নিচের কোনটি সত্য?
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)` কী কাজ করে?
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…
একটি কপি কনস্ট্রাক্টর হল একটি কনস্ট্রাক্টর যা…
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` স্টেটমেন্ট সাধারণত এড়ানো হয় কারণ…
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” সম্পর্ক কীভাবে উপস্থাপন করা হয়?
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` রিটার্ন করে?
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++ বৈশিষ্ট্য একটি ফাংশন বা ক্লাসকে পুনরায় লেখা ছাড়াই বিভিন্ন ডেটা টাইপের সাথে কাজ করার অনুমতি দেয়?
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` কী?
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]` সর্বদা প্রোগ্রামের নাম হয়।