0% found this document useful (0 votes)
10 views

C Programming MCQ Question Paper

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

C Programming MCQ Question Paper

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

1. What is the correct line to assign 85.5 to `s1.marks` 4.

What will be the output of the following code using a


in the code below? union `Person`?
struct Student { union Person {
string name; char name[20];
int rollNo; int age;
float marks; };
}; int main() {
Person p1;
int main() { strcpy(p1.name, "Alice");
Student s1; cout << p1.name << endl;
s1.name = "John"; p1.age = 25;
s1.rollNo = 10; cout << p1.age << endl;
// Missing line return 0;
cout << "Student Name: " << s1.name << ", Marks: " }
<< s1.marks; a) Alice
} b) 25
a) s1.marks = 85.5; c) Alice and 25 (in sequence)
b) s1.marks == 85.5; d) Undefined behavior
c) s1.marks(85.5); 5. What is the missing line to print `x` and `y` values of
d) marks = 85.5; the `Point` structure?
2. Which of the following is a correct definition of a struct Point {
structure `Book` with members `title`, `author`, and int x, y;
`price`? };
a) struct Book { char title[50]; char author[50]; int
price; }; void printPoint(Point p) {
b) struct Book { char title[50], author[50], // Missing line
price[50]; }; }
c) struct Book { int title, author, price; }; int main() {
d) Book { string title, string author, float price; }; Point p1 = {10, 20};
3. What is the missing line to print `Car` model and printPoint(p1);
price? }
typedef struct { a) cout << "x: " << p.x << ", y: " << p.y;
char model[20]; b) printf("x = %d, y = %d", x, y);
int year; c) cout << p.x << " " << p.y;
float price; d) cout << x << " " << y;
} Car; 6. Which of the following is the correct way to define an
enumerated type `Days` and print the integer value of
int main() { `Monday`?
Car c1 = {"Toyota", 2022, 30000}; a) enum Days {Monday, Tuesday}; cout << Monday;
// Missing line b) typedef enum {Monday, Tuesday} Days; cout <<
} Monday;
a) cout << c1.model << ", " << c1.price; c) Days Monday = 1; cout << Monday;
b) printf("%s, %f", c1.model, c1.price); d) cout << Days::Monday;
c) cout << "Model: " << model << ", Price: " << 7. What is the missing line in the function `areaOfCircle`?
price; #define PI 3.14159
d) printf("%s, %f", model, price); float areaOfCircle(float radius) {
// Missing line
}
int main() {
float radius = 5.0;
cout << "Area: " << areaOfCircle(radius);
}
a) return PI * radius * radius;
b) area = PI * radius * radius; return area;
c) return radius * radius;
d) area = PI * radius;
8. What is the correct syntax for defining an 12. What is the output of the following code using a
`Employee` using `typedef`? structure `Time`?
a) typedef struct Employee { string name; int id; struct Time {
float salary; }; int hours, minutes, seconds;
b) typedef struct Employee { name; id; salary; }; };
c) typedef struct { string name; int id; float salary; } int main() {
Employee; Time t1 = {2, 30, 45};
d) struct { string name; int id; float salary; } cout << t1.hours << ":" << t1.minutes << ":" <<
typedef Employee; t1.seconds;
9. What is the missing line to assign width to `r1` and }
print the area of the rectangle? a) 2:30:45
struct Rectangle { b) 02:30:45
int length, width; c) 2h 30m 45s
}; d) 2.30.45
13. Which of the following is NOT a user-defined data
int main() { type in C++?
Rectangle r1; a) struct
r1.length = 10; b) enum
// Missing line c) typedef
cout << "Area: " << r1.length * r1.width; d) int
} 14. Which preprocessor directive is used to include
a) r1.width = 20; header files in a C/C++ program?
b) Rectangle.width = 20; a) #define
c) r1.width(20); b) #include
d) width = 20; c) #ifdef
10. Which of the following is correct for defining and d) #endif
using a `Currency` union? 15. What is the main difference between `typedef` and
a) union Currency { int dollars; float rupees; }; `#define`?
Currency c1; a) `#define` is for constants, `typedef` is for data
b) typedef union { int dollars; float rupees; } types
Currency; Currency c1; b) `#define` creates macros, `typedef` defines data
c) typedef union { dollars; rupees; } Currency; types
d) union { int dollars; float rupees; } typedef c) `typedef` is a function, `#define` is a data type
Currency; d) Both are used for defining constants
11. What is the correct missing line to initialize the
array `arr` with zero values?
#define MAX 100
int arr[MAX];
for (int i = 0; i < MAX; i++) {
// Missing line
}
a) arr[i] = 0;
b) initialize(arr, 0);
c) arr = 0;
d) arr[i] == 0;

You might also like