Navigation überspringen
Day (14) / 365 💻 | C++ Interview Challenge (Video 2)
0:00

Day (14) / 365 💻 | C++ Interview Challenge (Video 2)

#include #cppinterview #cppprogramming

Day (14) / 365 💻 | C++ Interview Challenge (Video 2) These are real interview-level questions. If you rely on memorization, you will fail this. This challenge focuses on: • Pointers • String literals • Pointer arithmetic • Output-based traps ⚠️ Rules • 1 question • 3 confusing options • Comment your answer • No guessing 💡 Today’s Question: What will be the output of this C++ program? #include using namespace std; int main() { const char *str = "HELLO"; const char *p = str + 1; cout << p << endl; return 0; } A) HELLO B) ELLO C) H D) Compilation Error ✅ Correct Answer: B) ELLO 🧠 Why this is correct: str points to the string literal "HELLO" str + 1 moves the pointer one character forward Now p points to 'E' instead of 'H' Printing a char* with cout prints characters until '\0' So output becomes: 👉 ELLO Key concept: 👉 Pointer arithmetic + null-terminated strings Interviews don’t test syntax. They test how deeply you understand memory and pointers. #cppinterview #cppprogramming #pointerarithmetic #codingquiz programminginterview developers interviewprep cptraps

Kommentare

Kommentare aus dem Originalbeitrag auf Instagram

Noch keine Kommentare