Answer to Question #325448 in C for Anju

Question #325448

Consider the following declaration and the statements (a) to (d) written in C. Identify the statement which are correct and the ones which has an error, by giving reason. If a statement has an error correct it.

int c = 1, *pc; // declaration

(a) pc = c;

(b) *pc = &c;

(c) pc = &c;

(d) *pc = c; 


1
Expert's answer
2022-04-07T13:13:33-0400

(a) has an error. pc is a pointer so it should point to some memory. Correct expression is

pc = &c;


(b) is incorrect. *pc is dereference, that is the value which hold by the address pc, while &c is an address of variable c. Correct expression is

pc = &c;

(c) pc = &c; // is a correct expression

(d) *pc = c; // is a correct expression, provided that before pc was correctly initialized (as in (c))


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS