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

Discussion

 

int i = 5; is a statement in a C program.

  • A.during execution, value of i may change but not its address
  • B.during execution both the address and value may change
  • C.repeated execution may result in different addresses for i
  • D.i may not have an associated address

Answer: C

Correct answer: repeated execution may result in different addresses for i

The declaration int i = 5; inside a function creates an object with automatic storage duration: it is allocated when the block is entered and released when it is left.

Nothing fixes where. A recursive call, a different call path, or simply a different run of the program can place it at a different address, and modern systems randomise the stack deliberately. Within a single lifetime the address is stable and the value may change; across lifetimes neither the address nor the value carries over.

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

Post your comment

Please log in or register to post a comment.