Unit 6 - Practice Quiz
CSE101
1 Which keyword is used to declare a structure in C/C++?
class
struct
structure
object
2
In the following structure declaration, what is s1?
c
struct Student {
int id;
char name[20];
} s1;
3 Which operator is used to access a member of a structure using a structure variable?
->)
.)
::)
*)
4
Given the pointer ptr pointing to a structure variable, which syntax correctly accesses the member age?
ptr.age
ptr->age
*ptr.age
ptr::age
5 What is the primary difference between a Structure and a Union regarding memory allocation?
6
Consider the following union. Assuming int is 4 bytes and char is 1 byte, what is the size of u?
c
union Data {
int i;
char c;
} u;
7
In C++, which header file is required to use cin and cout?
<stdio.h>
<conio.h>
<iostream>
<fstream>
8
Which operator is used with cout for outputting data?
>>)
<<)
::)
.)
9
Which namespace must be used or included to access standard C++ libraries like cout without the std:: prefix?
using standard namespace;
using namespace std;
include namespace std;
define namespace std;
10
What is the default access specifier for members of a class in C++?
public
private
protected
internal
11
What is the default access specifier for members of a struct in C++?
public
private
protected
static
12 How do you access a global variable if there is a local variable with the same name in the current scope?
extern keyword
::
global keyword
13
Which of the following correctly defines a class named Box?
class Box { ... }
class Box { ... };
struct Box { ... }
object Box { ... };
14 What is an inline function?
15 Member functions defined inside the class body are treated as:
static functions
virtual functions
inline functions
private functions
16 Which keyword is used to declare a static data member in a class?
const
extern
static
volatile
17 Which of the following is true about static data members?
18 How are static data members typically initialized?
19 What is a characteristic of static member functions?
this pointer.
20 Which programming paradigm focuses on 'functions' and 'procedures' acting on data?
21 Which programming paradigm focuses on modeling real-world entities using 'objects'?
22 In Object-Oriented Programming, what is the term for wrapping data and functions together into a single unit?
23
Consider the following nested structure:
c
struct Date { int d, m, y; };
struct Emp {
int id;
struct Date dob;
} e1;
How do you access the month m of employee e1?
e1.m
e1.Date.m
e1.dob.m
dob.m
24
What happens if you assign one structure variable to another of the same type (e.g., struct1 = struct2)?
25
What is the correct syntax to define a method display outside the class MyClass?
void display() { ... }
void MyClass.display() { ... }
void MyClass::display() { ... }
void MyClass->display() { ... }
26
Which of the following is valid regarding initialized structures?
c
struct Point { int x; int y; };
struct Point p = {10, 20};
p.x is 10 and p.y is 20
p.x is 20 and p.y is 10
p.x is 10 and p.y is undefined
27 Procedural programming generally follows which design approach?
28
What is an Enumeration (enum)?
29
In the following enum, what is the value of BLUE?
c
enum Colors { RED, GREEN=5, BLUE };
30
Which operator is used to extract data from the input stream cin?
<<
>>
&
::
31
Which of the following statements about unions is FALSE?
32 Can a structure contain a pointer to itself?
static.
33 What is the size of an empty class in C++?
34 In the context of OOP, an Object is an instance of a __.
35
Why is typedef often used with structures in C?
struct isn't needed for variable declaration.
36
What is the output of the following C++ snippet?
cpp
int x = 10;
void func() {
int x = 20;
cout << ::x;
}
37 When passing a structure to a function by value:
38
Which syntax creates an array of 50 Student structures?
struct Student list[50];
struct list[50] Student;
Student list;
int list[50];
39 In C++, which keyword is used to bring a specific member of a namespace into the current scope?
include
using
import
scope
40
What does the keyword private imply in a class?
41 Which of the following is NOT a feature of Object-Oriented Programming?
42 What is the memory alignment/padding in structures?
43
Can functions be defined inside a struct in C (standard C99)?
44
If a member function is defined outside the class, how can it be made inline?
inline keyword in the function definition.
static keyword.
45
What is the result of the following pointer arithmetic?
c
struct Demo { int a; char b; }; // Assume sizeof(Demo) is 8 bytes due to padding
struct Demo ptr = (struct Demo )1000;
ptr++;
What is the value of ptr?
46
Which syntax allows multiple variables a, b, and c to be output in a single statement?
cout << a, b, c;
cout << a << b << c;
cout >> a >> b >> c;
cout.print(a, b, c);
47
What is the scope of a class member declared as public?
48
In the declaration union Data { int x; float y; };, if we assign x = 10 and then y = 5.5, what happens to x?
x remains 10.
x is converted to integer 5.
x becomes garbage/corrupted because memory is overwritten.
x is moved to a new address.
49
Which of the following creates an object obj of class Test?
class Test obj;
Test obj;
obj : Test;
new Test obj;
50 Which symbol terminates a C++ statement (like a function call or declaration)?
:
.
;
}