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
votes
1 answer

Java Unexped Outputs From Pre-Increment

I am trying to figure out why the following code gives two different results I tried the followingL int x = 4, y = 4; System.out.println(x + --x); System.out.println(--y + y); And It outputs 7 6. From my knowledge, preincrement has a higher…
-1
votes
1 answer

Prefix and postfix operator

#include int main() { int x=5, y; y=x+++x; printf("%d", x); printf("%d", y); } What I found is that postfix increment has higher precedence than prefix. Hence y=x+++x; y=(x++)+x; y=10 x=6 But when I execute the program…
-1
votes
1 answer

Why is the output of the following program showing compile time error?

Why is the output of the following program showing compile time error? Please explain "lvalue required" #include int main() { int a=5; printf("%d", ++a++); return 0; }
-1
votes
1 answer

Pre Increment and end of string

Suppose I have this code section char *ptr[] = {"Hi", "Alexa"}; std::cout<<++*ptr<
supnep
  • 45
  • 6
-1
votes
2 answers

Issue with variable values in C (huge numbers)

I'm just start to learn C and I came across with an exercise to count the number of new lines(\n), blank spaces and tabs(\t) in stdin. The question is, Why: #include int main(void){ int c, nl, ns, nt = 0; while ((c = getchar())…
-1
votes
1 answer

When does a function call copy its pass-by-value arguments relative to the argument sequences?

I would like to understand this code snippet as much as the undefined behavior permits it: int i = 0; printf("%d %d %d", i, ++i, i++); output: 2 2 0 From what I can tell: a comma , defines a sequence the actual printing happens when all of the…
-1
votes
1 answer

Evaluation of post and pre increment in java

Evaluate the following Java expression, if k=3, l=5, and m=10: ++m + l - l + m + k++ Would the answer be: (++10) +5 -5 +10 +3 =11 +5 -5 +10 +3 =24 Or, would this be evaluated as: 11 +5 -5 +11 +3 which results to 25?
R Ny
  • 27
  • 5
-1
votes
2 answers

Why the output is showing 3 1 3 can anyone help me in this in C

#include int main() { int i = 1; printf("%d %d %d",++i,i++,i); return 0; }
First last
  • 29
  • 5
-1
votes
1 answer

Why n++==--n always equal to 1?

Why n++==--n always equal to 1? The following code gives output as 1. #include int main(){ int n=10; printf("%d\n",n++==--n); } The output is always 1, no matter what n is.
-1
votes
1 answer

Loop runs one more time than I expected

class BlankIt{ public static void main(String[] args) { int i = 10, j = 20; while(i++ < --j){ System.out.println("\n " + i + " " + j); } System.out.println("\n " + i + " " + j); } } The…
user11718102
-1
votes
1 answer

Strange behavior with post and pre increment operators in C

When I do this - int i = 4; printf("\n %d", ++i + ++i); I get 12 as the answer. But when I do this - int i = 4; int a,b,s; a = ++i; b= ++i; s = a+b; printf("%d", s); I get 11 as the answer. Why? I have tried both the code. The expected value is 11…
-1
votes
3 answers

Not getting expected output from this code using logical operators and pre/post increment

I am not getting expected output in the following C code main(){ int i=0,j=-2,k=0,m; if((!i||--j&&k++)&&(i++||j++&&!k++)) { printf("i=%d j=%d k=%d",i,j,k); } return 0; } I got the output in compiler as : i=1 j=-1…
chesslad
  • 171
  • 7
-1
votes
1 answer

Undefined Behaviour in C [with example]

I had been going over a few tricky and unusual behaviour that C code snippets produce, and I came across one that resulted an unusual output. int main() { int i=3; printf("%d%d%d", i, ++i, i++); return 0; } I thought this would have…
-1
votes
1 answer

Output is less than expected after using incrementer operator

I create a class abc and static variable and two function having name setsize in which I set a value and another function I create a getsize to get value in getsize function I increment a value when I call a function its output must be 101 but it…
-1
votes
1 answer

Pre-increment in recursive call

I was solving this leetcode question https://leetcode.com/problems/binary-tree-right-side-view/description/ . The following code works correctly. class Solution { public List rightSideView(TreeNode root) { List ans =…
George Francis
  • 462
  • 2
  • 7
  • 16