Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of C program with arrays?

int main() 
{ 
int a[3] = {20,30,40}; 
int b[3]; 
b=a; 
printf("%d", b[0]); 
}

 

  • A.Compiler Error
  • B.Output : 20
  • C.Output : 30
  • D.Output : 0

Answer: A

Correct answer: Compiler Error

An array is not assignable. b = a; fails because b is not a modifiable lvalue - the name denotes fixed storage, not a pointer variable that could be repointed. Copying an array means copying its elements, with a loop or with memcpy(b, a, sizeof(a)).

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.