English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Given the following declarations:
char a[ ] = "abc", *p = "def";

What is the effect of the following statement?

p=a

a. It copies the string "abc" into string p

b. It changes p to point to string "abc"

c. It copies the first character of a ton the first character of p

d. It generates an error

2006-09-01 08:37:46 · 7 answers · asked by Anonymous in Computers & Internet Programming & Design

7 answers

haha cheater.

ya D) is looking good.

2006-09-01 08:41:57 · answer #1 · answered by steven p 2 · 0 1

Usually it would be b. Because you replaced the adress the pointer points at. But i am not quite sure you can declare a pointer on a string constant (*p="def") - it would probably generate an error.

2006-09-01 15:44:20 · answer #2 · answered by Bax 2 · 0 0

Genrates Error

2006-09-01 15:39:50 · answer #3 · answered by rockiee80 3 · 0 0

p will then point to the first position of a, it won't point to the whole string but you can use pointer arithmatic to get the rest of the string. So - E. none of the above.

2006-09-01 16:34:58 · answer #4 · answered by John J 6 · 0 0

The answer is b.

I just wrote a little code to do it, although I should have been smart and just looked at K&R.

2006-09-01 15:47:14 · answer #5 · answered by TJ 6 · 0 0

b.
p is a pointer to char.
The name of the array a is also a pointer to char.

2006-09-01 15:43:35 · answer #6 · answered by rt11guru 6 · 0 0

b. p will point to a which contains "abc".

2006-09-01 15:43:27 · answer #7 · answered by bee 3 · 0 0

fedest.com, questions and answers