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

Given the following declaration
char a[ ] = "cba', *p=a;
what is the difference between the values of te expression ++*p and *++P?

2006-08-31 14:38:28 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

The options I have are:
a. The first is equal to d, and the second one is equal to b.

b. The first is equal to c, and the second one is equal to a.

c. The first causes a complier error, while the second does not

d. The two expressions have the same value.

2006-08-31 15:14:40 · update #1

2 answers

++*p == 'e'
*++p == 'a'

in the first you deference *p first which is equivalent to ++a[0]
in the second you increment the pointer twice and then deference it.

2006-08-31 17:03:10 · answer #1 · answered by run4ever79 3 · 0 0

Isn't this a C/C++ question? C#, like Java, don't deal with pointer arithmetic nor do they use char array as string; they use String objects and use references replacing pointers altogether.

p* -> "c", one of them is adding 1 to the dereferenced result of *p (answer is "c" + 1 = "d"; that is ++*p) while the other is dereferencing a pointer that would be 1 next to where "c" is in memory, so "b" is the answer (*++p)

2006-08-31 14:59:07 · answer #2 · answered by Andy T 7 · 0 0

fedest.com, questions and answers