Questions tagged [pre-increment]

For issues relating to defining or performing pre increment operations.

Pre-increment operators increase the value of their operand by 1 (or another specified amount), and the value of the operand in the expression is the operand's value after the increment operation.

342 questions
1
vote
1 answer

C++ pre-increment vs post-increment on char* pointer while assigning a value

so I get it that pre-increment is faster than post-increment as no copy of the value is made. But let's say I have this: char * temp = "abc"; char c = 0; Now if I want to assign 'a' to c and increment temp so that it now points to 'b' I would do…
1
vote
1 answer

Why this is invalid C code?

If x is of type int, for what I understand, ++x is a lvalue, so ++x = 5; is valid. But the compiler doesn't like it. It days that lvalue required as left operand of assignment What is happening here? Isn't ++x an lvalue?
Garmekain
  • 664
  • 5
  • 18
1
vote
4 answers

equivalent expression for a[j++] = ++i without using pre or post increment operators

So I am pondering this question (this is a homework/exam review problem): Write down an equivalent expression for a[j++] = ++i; without using pre/post increment operators. If no such expression can be provided explain why. I was able to come up with…
Grant
  • 532
  • 2
  • 7
  • 21
1
vote
2 answers

Assigning an incremented variable

PORTB = pattern ++; //The author explains te upper code with the code below pattern = pattern + 1; PORTB = pattern; PORTB = ++ pattern; //That's what I think is right I think this code is wrong, as the post-increment should add 1, after using it…
some_user
  • 179
  • 11
1
vote
8 answers

Operator Precedence.. () and ++

Salute.. I have an unusual problem. Here in this table in MSDN library we can see that precedence of () is higher than ++ (Pre-increment) . but when I run this code, it seems that precedence of ++(prefex) is higher: int main() { int a=3,b=2,x; …
C77431
  • 99
  • 3
  • 8
1
vote
2 answers

Post and Pre Increment Operator OCJA-1.8

I am practicing the java post and pre increment operators where I have a confusion to understand the output of the below program. How it have generated the output as "8" ? public class Test{ public static void main(String [] args){ int x=0; …
Gaurav Pathak
  • 2,576
  • 1
  • 10
  • 20
1
vote
4 answers

Not able to understand the working of Pre-increment/ Pre-decrement in C++

Can someone please explain what is happening in the following code? (Taken from GeeksForGeeks) int main(){ int a = 10; ++a = 20; // works printf("a = %d", a); getchar(); return 0; } What exactly is happening when the statement ++a = 20 is…
1
vote
1 answer

Java increment i = i++;

public static void main(String[] args) { int i = 0; i = i++; System.out.println(i); } This java code is printing value 0. How internally java assign value 0 to i instead of 1 ?
Shankar Modi
  • 71
  • 1
  • 1
  • 4
1
vote
5 answers

is there a reason to use ++$i in for loop?

i have following code for loop for ($i=0; $i<=(count($subusers)-1); ++$i) { is there a reason to use ++$i instead of $i++ if latter doing same thing?
llamerr
  • 2,997
  • 4
  • 29
  • 40
1
vote
3 answers

C, pre and post increment, different answers in different programs

testing some code when studying C language, #include #include #define hypotenusa(x, y) sqrt((x) * (x) + (y) * (y)) int main(void) { int a, x; x = 2; a = hypotenusa(++x, ++x); printf("%d\n", a); } And I am…
mikeN
  • 29
  • 4
1
vote
4 answers

Difference between arr[0]++ and ++arr[0]

In C#, is there a difference between the code (all in one statement, not part of a larger one) arr[0]++; and ++arr[0]; I fully understand, that in C / C++ / Objective-C, that this would not do the same thing, first case would get the value at arr's…
Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
1
vote
4 answers

Can't increment pointer position

Why I can not increment the position of the pointer array? typedef char SmallBuffer[20]; SmallBuffer sb2, sb1 = "wtf!"; while(*sb1 != '\0'){ ..... ++sb1; } when compiling the gcc compiler returns : main.c:19:38: error: lvalue…
Gonzalez
  • 209
  • 1
  • 2
  • 8
1
vote
3 answers

Update value not incrementing in Javascript

I am trying to increment a value by one each time but its not working. My variable currentValue gives me 0 as expected but when i try increment it using var newValue = currentValue ++; it still gives me 0. function updateClicks(e, maxValue) { …
red house 87
  • 1,837
  • 9
  • 50
  • 99
1
vote
1 answer

Output of multiple post and pre increments in one statement

I'm new to C language so please sum1 help me out. A C code written int i=3; printf("%d",++i + ++i); Complier gives O/P =9. How?
1
vote
1 answer

what is the output and explain how?

I am confused about the output of following 2 programs. Could someone explain the precedence and associativity rules? Program 1: char arr[] = "geeksforgeeks"; char *p = arr; *p++; printf(" %c", *p); Program 2: char arr[] = "geeksforgeeks"; char…