24.3k views
15 votes
Given the following code char a[2][4] = { { 'c', 'a', 'r', 'b' }, { 'i', 'k', 'e', '\0' } }; char *p = &a[0][0]; while (*p != '\0') { printf("%c", *p); p++; } what will happen? group of answer choices a compilation error will occur at this line: char *p = &a[0][0]; it prints: carbike it prints: carb a compilation error will occur at this line:

1 Answer

6 votes

Answer:

You'd get a compiling error.

Step-by-step explanation:

Since this code is presumably written in C++, it doesn't include an "int main()", and without it you'll have a compiling error when you create functions. Since the start of a C++ program is looking for "int main()" and one doesn't exist, the program cannot compile.

Since the only function here is the while statement, then that's what the compiler will scream at you for. If you put all of this code within an "int main()", you'll no longer have a compiling error, and you'll have "carbike" written to the console.

I hope this explanation helps! You're welcome!

User Marcusficner
by
6.8k points