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

it is a c language question ask in interview

2007-03-08 01:42:28 · 4 answers · asked by engg 1 in Computers & Internet Programming & Design

4 answers

It is an increment that happens before or after the variable is returned. The * indicates p must be a pointer.

If p is 3, then

p++ will return 3 and then increment p by 1, which means p is 4

++p will increment p by 1, which means p is 4, then return p.

2007-03-08 01:49:10 · answer #1 · answered by Rex M 6 · 1 0

Easy.
One p is in the prefix form and another one is in postfix form.
Let take an example to explain
x=1;
y=++x;
Ans y=2 and then x=2
We first increment x, like y=x+1 where x=1

x=1;
y=x++
Ans y=1 and then x=2
We first check for y since the + sign is found behind x. We put y=1 and then increment x.

Tips: Look for the position of the sign and then calculate. It will help u.

2007-03-08 09:59:41 · answer #2 · answered by Tubby 5 · 1 1

*p++ returns the contents at p and then increments p by the size of the type that p points to.

++*p returns the contents of p incremented by 1.

If char *p = "159"
ch = *p++ would return '1' and then p would = "59"
ch would = '1'

If char *p = "159"
ch = ++*p would increment the value at p
ch would = '2' and p = "259"

2007-03-08 10:58:42 · answer #3 · answered by Tempest 3 · 0 1

*p++ it is add a one to 'p' and then it is return and it will return and then add a one as 'p' is a pointer

2007-03-08 09:58:26 · answer #4 · answered by OMAR 1 · 0 2

fedest.com, questions and answers