Knowee
Questions
Features
Study Tools

What will be the output of the following code?#include <stdio.h>int main() {    int arr[4] = {0, 1, 2, 3};    printf("%d\n", arr[-1]);    return 0;}

Question

What will be the output of the following code?#include <stdio.h>int main() {    int arr[4] = {0, 1, 2, 3};    printf("%d\n", arr[-1]);    return 0;}

🧐 Not the exact question you are looking for?Go ask a question

Solution

The code will result in undefined behavior. In C, array indexing is based on offset from the base address. So, arr[-1] is trying to access the memory location before the start of the array, which is not defined. It might crash or it might print some garbage value, depending on the system and compiler.

Similar Questions

What will be the output of the following program?

What will be the output of the following C code?

What will be the output of the following C++ code?

What is the output of the following code in Python?

What will print out when the following code runs?

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.