DEV Community

Farhan Ahmad
Farhan Ahmad

Posted on

10 C++ Interview Questions Every Beginner Should Be Able to Answer

If you are learning C++ for a university exam, a lab viva, or your first job interview, the same basic questions come up again and again. Here are ten of them with short, clear answers.

1. What is the difference between = and ==?

= assigns a value (x = 5;). == compares two values (if (x == 5)). Writing if (x = 5) compiles, but it assigns 5 and is always true — a classic bug.

2. What is the difference between a compiler and an interpreter?

A compiler translates the whole program into machine code before it runs (C++ does this). An interpreter translates and runs code line by line (like Python).

3. What are the basic data types in C++?

int (whole numbers), float and double (decimals), char (a single character), and bool (true/false). std::string is used for text.

4. What is the difference between while and do-while?

while checks the condition first, so it may run zero times. do-while checks at the end, so it always runs at least once.

5. What is a function, and why use one?

A named block of code that does one job. Functions remove repetition, make code easier to test, and make programs easier to read.

6. Pass by value vs pass by reference?

By value, the function gets a copy, so changes don't affect the original. By reference (int &x), the function works on the original variable.

7. What is an array?

A fixed-size collection of elements of the same type stored next to each other in memory. Indexes start at 0, so int a[5] goes from a[0] to a[4].

8. What is a pointer?

A variable that stores a memory address. int *p = &x; makes p point to x, and *p gives the value of x.

9. What is the difference between a structure and a class?

Both group related data. In a struct, members are public by default; in a class, they are private by default.

10. Why do we write return 0; in main()?

It tells the operating system the program ended successfully. A non-zero value usually means an error.


Practise answering these out loud — that is exactly how vivas and interviews test you.

I put 30 of these questions, a quick-revision cheat sheet, and 75 tested programs into a beginner-friendly ebook. If you want the full set, it's C++ Programming for Beginners ($9): https://farhanbreeze4.gumroad.com/l/kxwlwo

Which question would you add to this list? Let me know in the comments.

Top comments (1)

Collapse
 
dharu_89ac9b8f48aa5d359f6 profile image
Dharu •

Great and concise list! Perfect quick-refresher for lab vivas and entry-level interviews.

To answer your question at the end: I would definitely add "What is the difference between dynamic memory allocation using new/delete vs stack memory?" or "What is a reference vs a pointer?" — candidates often mix those up when starting out with C++.

Thanks for sharing this post! 🙌