What will be the output of the following C code? #include int main() { int ary[4] = {1, 2, 3, 4}; printf("%d\n", *ary); }a.1b.Compile time errorc.Some garbage valued.Undefined variable
Question
What will be the output of the following C code? #include int main() { int ary[4] = {1, 2, 3, 4}; printf("%d\n", *ary); }a.1b.Compile time errorc.Some garbage valued.Undefined variable
Solution
The output of the given C code will be '1'.
Here's the step by step explanation:
-
An array 'ary' of integers is declared and initialized with the values 1, 2, 3, 4.
-
The printf function is used to print the value of '*ary'.
-
In C, the name of the array 'ary' is a pointer to the first element of the array. Therefore, '*ary' is equivalent to 'ary[0]'.
-
Hence, the value '1' which is the first element of the array 'ary' will be printed.
So, the correct answer is a.1.
Similar Questions
what will be the output of the c program?
What will be the output of the following code?
What will be the output of the following C++ code?
What will be the output of the following program?
What will be the output of the following C code?#include <stdio.h>int main() { int i; for (i = 0; i < 5; i++); printf("%d\n", i); return 0;}
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.