Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
1 answer
38 views

private static int fib(int zero, int one, int x, int s) { if(x==0) return s; zero = one; one = s; s= zero + one; return fib(zero,one,x--,s); } private static int fib(int zero,...
Arif Ahmed Arif's user avatar
-1 votes
1 answer
62 views

I'm studying about postfix increment operator in JAVA, and curious about why the result is 6 when coding like this. int b = 3; b += b++; System.out.println(b); I think that due to the += ...
moni's user avatar
  • 7
1 vote
5 answers
254 views

So I'm quite confused as to how the post-increment is not evaluated first. (According to precedence post-increment comes first.) Can someone please explain this? Consider the code given below: int ...
Yuu's user avatar
  • 39
0 votes
0 answers
50 views

Overloading problem. I have tried to overload Postfix++ operator in a class then I saw a strange behaviour whenever I try to do this cout << oldValue <<" "<< oldValue++;...
Ali El-Sayed's user avatar
0 votes
0 answers
67 views

I wrote a simple code for printf in C with unary prefix operator as the following: #include <stdio.h> int main() { int i=5; printf("%d %d %d",++i,i,i+1); return 0; } And ...
Viraj's user avatar
  • 1
0 votes
2 answers
67 views

I am trying to see how endianness applies on my system. Using Python sys module, I found that its little endian, which means that least significant bytes are at lower memory addresses. So, I wanted to ...
user9026's user avatar
  • 970
1 vote
4 answers
164 views

I just came across this C question with the following code: int fun(); int main() { for (fun(); fun(); fun()) printf("%d\n", fun()); return 0; } int fun() { int static n = ...
bharath2438's user avatar
0 votes
3 answers
95 views

This works fine because we are using the prefix decrement operator in the recursive call ! public static void main(String[] args) { doubt1(5); } Prefix Decrement: static void doubt(int num) { ...
Tholkappiar's user avatar
1 vote
3 answers
78 views

I have a code that defines a simple enumerated type, then loop through it to print the corresponding syllable. #include <stdio.h> typedef enum syllable { Do=1, Re=2, Mi=3, Fa=4, So=5, La=6, ...
Kim Minseo's user avatar
0 votes
1 answer
48 views

int a = 6; int b = a + a++; answer is 12 int a = 6; int c = a++ + a; answer is 13 why are the answers for b and c are different ? since postfix has higher a precedence value, then the answer ...
Harry's user avatar
  • 11
3 votes
3 answers
294 views

#include<stdio.h> int main() { int a=4; int b=4; int c= a++ < ++b? 1 : 0; printf ("%d",c); } It is known that there is a sequence point at ?, which means that ...
user2277550's user avatar
-1 votes
1 answer
53 views

#include <stdio.h> 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 ...
Subham Bhuyan's user avatar
0 votes
0 answers
49 views

the output of the code below are different between g++ and clang++ ! I think clang++ is correct, what do you think? g++ output: 11 4 13 7 clang++ output: 11 4 11 8 #include <iostream> struct A { ...
Ammar Tamimi's user avatar
-1 votes
1 answer
72 views

How the value of m is 2 after execution as i is postfix ? int main() { int i,m; int a[5]={8,10,1,14,16}; i=++a[2]; m=a[i++]; cout<<i<<m; return 0; }
Frnaz Akbar's user avatar
0 votes
1 answer
500 views

what I have so far is: Stack = ArrayStack() def evaluate(postfix_str, Stack): for c in postfix_str: if c not in '+-*/()': Stack.push(int(c)) else: c....
Bella 's user avatar
2 votes
1 answer
83 views

I am learning java and this logic makes me feel confused. Isn't here i=20(+1)+20(+1)? Why 41 instead of 42? jshell> int i = 20 i ==> 20 jshell> i=i++ + i++ i ==> 41 See this code run at ...
Jack's user avatar
  • 23
0 votes
2 answers
952 views

I made a function infixToPostfix() which converts an infix expression to a postfix expression. But my program generates no output on running. Please point out the errors in my program. Code: #include &...
Ultimate's user avatar
0 votes
2 answers
767 views

I am not able to understand prefix operator behaviour in scenario when it is used multiple times in a statement . Here is an example code to illustrate my problem #include<iostream> using ...
user1371666's user avatar
1 vote
3 answers
50 views

When I was doing the practice questions today, I found that the outputs of printf("%d\n",x--); and printf("%d\n",x); are the same. I changed it to printf("%d\n",x++); and ...
huahua sun's user avatar
0 votes
1 answer
124 views

I found a lot information how to overload decrement(--) operators if your class has an int value. But I can not understand how to do the same with classes which contain structures which contain int ...
Etnim's user avatar
  • 77
0 votes
2 answers
848 views

below is code for operator overloading for unary operator ++ #include <iostream> using namespace std; class Distance { private: int feet; // 0 to infinite int inches;...
rohit choudhari's user avatar
1 vote
1 answer
63 views

Let's say you have the code as follows: float arr[] = { 0.0f, 1.0f, 62.0f, 400.0f }; Then I print this out as follows: printf("%lu\n", sizeof(0[arr])); Why does it return 4,...
sentrix's user avatar
  • 39
1 vote
1 answer
156 views

output in this case is 1 int main() { int i = 500; while( (i++) != 0 ); printf("%d\n", i); return; } output in this case is 0 int main() { int i = 500; while( (i=i+1)...
ahmed khaled's user avatar
0 votes
0 answers
20 views

I am finding difficulty to understand how precedency works in the following case. Can anyone explain why the answer is different in below two printf functions? int main() { int a=10,b=20,c; c=...
Kamlesh Makvana's user avatar
0 votes
0 answers
122 views

#include <iostream> using namespace std; class A { int x, y; public: A(int a, int b) { x = a; y = b; } void out() { cout << "\nx="...
Satyabrata Kar's user avatar
1 vote
1 answer
172 views

Following the precedence operator in java 8 it is clear that the postfix operator (expr++ expr--) has a higher precedence that the unary operator, pre-unary operator (++expr --expr). However when ...
jav's user avatar
  • 13
0 votes
7 answers
535 views

The semicolon has been added after the first while loop, but why is the value of the i variable 3 here, where j is 2? #include<stdio.h> int main() { int i=1; while(i++<=1); ...
Shuvo mandol's user avatar
0 votes
3 answers
215 views

given that int w = 1; int x = 6; int y = 5; int z = 0; z = !z || !x && !y; printf("%d\n", z); z = x-- == y + 1; printf("%d\n", z); Could someone explain how the line ...
ell's user avatar
  • 25
3 votes
4 answers
3k views

I have this simple piece of code but I don't understand this part: sum += i++ . int num1 = 5; int sum = 0; if (num1 < 100) { for (int i = 0; i < num1; i++) sum += i++; //? ...
tokyo's user avatar
  • 69
-3 votes
3 answers
123 views

Code: #include <stdio.h> int main() { int i = 3; printf("%d %d %d %d %d\n",i = 7,--i,i = 18, i+5, i = 0); printf("%d %d %d %d %d\n",i = 7,i--,i = 18, i+5, i = 0);...
Vishesh Mehta's user avatar
1 vote
1 answer
93 views

#include<stdio.h> int main() { int a=0, b=1, c=3; *((a) ?&b :&a) = a ? b : c; printf("%d %d %d\n", a, b, c); return 0; } Output:3 1 3 The associativity for assignment ...
Shyam Prasanna's user avatar
1 vote
1 answer
46 views

func postFix(_ expr: String) -> Int { // write your code here let nums = expr.components(separatedBy:CharacterSet.decimalDigits.inverted) .joined() let set = CharacterSet(...
Adel Kazme's user avatar
0 votes
0 answers
22 views

Can anyone explain to me why the following code: #include <iostream> using namespace std; int main() { int y=3; int z = (--y) + (y=10); printf("%d \n", z); } prints out z=...
Quang Thinh Ha's user avatar
0 votes
1 answer
116 views

#include <stdio.h> int main() { int a = 1; int b = 1; int c = a || --b; int d = a-- && --b; printf("a=%d, b= %d, c= %d, d= %d",a,b,c,d); return 0; } In ...
prithvi2k2's user avatar
-2 votes
3 answers
134 views

a = 1; int a2 = a++; System.out.println("----------Test 3 ----------"); System.out.println("The value of a is " + a); System.out.println("The value of a2 is " + a2); ...
Emily Watson's user avatar
1 vote
1 answer
219 views

There is an example borrowed from CARM (C A Reference Manual, Samuel P. Harbison III, Guy L. Steele Jr., 2002, Prentice Hall), page 218-219. I write all of three code-chunk in one source: #include <...
Andrey Lanin's user avatar
1 vote
1 answer
66 views

I am trying to count number of combinations in given range and length of combinations. Here is following code. function generateCombination() { const perm = []; const permLength = 2; const ...
santy's user avatar
  • 310
13 votes
3 answers
316 views

I can't get my head around why the code below is not working as expected: #include <stdio.h> int main() { int i = 0, size = 9, oneOrZero[] = {1,1,1,1,1,1,1,1,0}; while (i < size &...
milancodes's user avatar
1 vote
1 answer
67 views

I bumped into a problem which prompted me to do some research. I have found that a piece of code like this: #include <stdio.h> int main(void) { char i = 0; i++ && puts("Hi!&...
Kaiyaha's user avatar
  • 480
-2 votes
1 answer
242 views

I am trying to write a C++ program to convert infix expressions to prefix and postfix. Where did I go wrong? How can I change code to delete parentheses at the last form (postfix)? Thanks for any help!...
Kushagra's user avatar
4 votes
1 answer
103 views

#include <cstdio> #include <iostream> using namespace std; class Int32 { int num; public: Int32(int num = 0) : num(num) {} ~Int32() {} int value() { return num; } ...
vinoth kumar's user avatar
3 votes
0 answers
77 views

I'm learning web development, and I got puzzled by the strange behavior of a certain code in JavaScript and PHP. JavaScript n = 10 n = n - n++ console.log(n) // outputs 0 PHP $n = 10; $n = $n - $n++; ...
vrintle's user avatar
  • 5,626
-2 votes
1 answer
239 views

Can you please explain this code, keeping in mind that the person who wrote it was using it to teach me the difference between prefix and postfix incrementations int main() { const int ROWS = 3;`...
Nella's user avatar
  • 3
-1 votes
1 answer
121 views

I have a piece of code #include <bits/stdc++.h> using namespace std; typedef long long ll ; int main() { ios_base::sync_with_stdio(0);cin.tie(0);...
securityapps2.0 hackathon's user avatar
1 vote
1 answer
75 views

namespace Randomedits { class Program { static void Main(string[] args) { int x = 2; int sml2 = ++x - (x++) ; Console.WriteLine(sml2); ...
Mohit Setia's user avatar
-1 votes
1 answer
175 views

def get_token_list(expr): token_list_initial = expr.split(' ') token_list=[] for token in token_list_initial: if token in '+-/*^()': token_list.append(token) elif ...
itlove's user avatar
  • 1
6 votes
1 answer
346 views

Although this question might be answered somewhere and I could not find it. Below written first statement work whereas second does not? WHY? int main() { int x = 1, y = 2; int *p = &++x; // ...
Hemant Bhargava's user avatar
-3 votes
1 answer
179 views

Given: int r=1; r=r++ + r++ + r++; System.out.println("r:" + r); Why is this returning 6 instead of 7. I can get the order of how the above is evaluated e.g. 1 + 2 + 3 = 6 but not sure why the last ...
tatamata's user avatar
0 votes
1 answer
169 views

I see those two main advantages to postfix over prefix notations for unary functions: nice formatting, no nesting maps better the Input -> Function -> Ouput way of thinking about data ...
montrivo's user avatar
  • 174
0 votes
1 answer
306 views

In Java, is a++ a postfix operator or an unary operator? In the Operator Precedence from Oracle, it is separated. Reference
Ko Ye's user avatar
  • 77