ExamVeda
Login
Home
This question belongs to C Program Arrays And Strings
Arrays and Strings
?

Which of the following statements are correct about the program below?
#include<stdio.h>
void main()
{
    int size, i;
    scanf("%d", &size);
    int arr[size];
    for(i=1; i<=size; i++)
    {
        scanf("%d", arr[i]);
        printf("%d", arr[i]);
    }
}

Answer & Solution
Correct Answer: Option A

The statement int arr[size]; produces an error, because we cannot initialize the size of array dynamically. Constant expression is required here.
Example: int arr[10];
One more point is there, that is, usually declaration is not allowed after calling any function in a current block of code. In the given program the declaration int arr[10]; is placed after a function call scanf().

Examveda
Question posted by Examveda
Community

Join the Discussion

5 Comments
Golam Muktadir
Golam Muktadir 4 years ago
No error, It works on Code block 20.03.
Important Not
Important Not 8 years ago
It has no error
Gopal Krishna
Gopal Krishna 9 years ago
No,those statements work without even generating warnings
Amar Raikwade
Amar Raikwade 10 years ago
& sign is also missing.
SHUBHAM SHASTRI
SHUBHAM SHASTRI 11 years ago
HERE WE WILL GET GARBAGE, AS VALUES OF ARRAY ARE NOT SCANNED BY &.......SO NO USE OF IT.