Login
Register
@
Dark Mode
Profile
Edit my Profile
Messages
My favorites
Register
Activity
Q&A
Questions
Unanswered
Tags
Subjects
Users
Ask
Previous Years
Blogs
New Blog
Exams
Dark Mode
what will be the output and why?
[closed]
Khushal Kumar
asked
in
Programming
Jul 7, 2017
closed
Apr 5, 2022
by
Arjun
425
views
3
votes
3
votes
closed as a duplicate of:
Undefined Behaviour in C
#include <stdio.h>
int
main()
{
int
i = 8;
int
p = i++*i++;
printf
(
"%d\n"
, p);
}
programming-in-c
Khushal Kumar
asked
in
Programming
Jul 7, 2017
closed
Apr 5, 2022
by
Arjun
by
Khushal Kumar
425
views
comment
Follow
share this
share
3 Comments
by
srestha
commented
Jul 7, 2017
reply
Follow
share this
Same these are compiler dependent.
1
1
by
Khushal Kumar
commented
Jul 7, 2017
reply
Follow
share this
But, according to you, what should be the output though? what ways the output will be given by the compiler and how does the different compilers carry out the result?
THANK YOU!
0
0
by
srestha
commented
Jul 7, 2017
reply
Follow
share this
read this
https://gateoverflow.in/62411/undefined-behaviour-in-c
1
1
Please
log in
or
register
to add a comment.
1
Answer
–2
votes
–2
votes
Answer is 72.
postfix increment is left to right associatively and the precedence of order is postfix increment > multiplication.
Step 1: i = 8
p = 8 * i++;
Step 2 : i++ i=9
p = 8 * 9
Step 3: i++ i=10
p=72
print p
Arnab Bhadra
answered
Jul 7, 2017
by
Arnab Bhadra
comment
Follow
share this
3 Comments
by
dd
commented
Jul 7, 2017
reply
Follow
share this
It has undefined behaviour
1
1
by
Bikram
commented
Jul 7, 2017
reply
Follow
share this
yes, it is undefined.
we can not say " postfix increment is left to right associatively " actually it depends upon C compiler to generate more optimized code .
0
0
by
amitraj123
commented
Apr 5, 2022
reply
Follow
share this
Above answer is wrong. Answer will be compiler dependent.
0
0
Please
log in
or
register
to add a comment.
← Previous
Next →
← Previous in category
Next in category →
Related questions
0
votes
0
votes
1
answer
1
Anirudh Kaushal
asked
in
Programming
Apr 5, 2022
158
views
What will be the output and Why?
#include<stdio.h> int main() { char num = '\011'; printf("%d",num); return 0; }
Anirudh Kaushal
asked
in
Programming
Apr 5, 2022
by
Anirudh Kaushal
158
views
programming-in-c
1
vote
1
vote
2
answers
2
Khushal Kumar
asked
in
Programming
Jul 7, 2017
374
views
what would be the output and why?
#include <stdio.h> int x = 20; int f1() { x = x+10; return x;} int f2() { x = x-5; return x;} int main() { int p = f1() + f2(); printf ("p = %d", p); return 0; }
Khushal Kumar
asked
in
Programming
Jul 7, 2017
by
Khushal Kumar
374
views
programming-in-c
0
votes
0
votes
1
answer
3
abhinowKatore
asked
in
Programming
Jan 18
139
views
Ace Test series |C programming | What will be the output of the following program ?
What will be the output of the following program ? answer is 8 but I am getting 5, please explain where I am wrong
abhinowKatore
asked
in
Programming
Jan 18
by
abhinowKatore
139
views
programming-in-c
recursion
2
votes
2
votes
0
answers
4
_shashi
asked
in
Programming
Jan 8, 2018
1,559
views
What will be the output of this C program
What will be the output of following programs : void fun1(struct node* head) { for(head == NULL) { return; } fun1(head->next); printf("%d ", head->data); } And this one ! void fun1(struct node* head) { while(head == NULL) { return; } fun1(head->next); printf("%d ", head->data); }
_shashi
asked
in
Programming
Jan 8, 2018
by
_shashi
1.6k
views
programming-in-c
linked-list
Subscribe to GATE CSE 2023 Test Series
Subscribe to GO Classes for GATE CSE 2023
Quick search syntax
tags
tag:apple
author
user:martin
title
title:apple
content
content:apple
exclude
-tag:apple
force match
+apple
views
views:100
score
score:10
answers
answers:2
is accepted
isaccepted:true
is closed
isclosed:true
Recent Posts
Recruitment of Scientific Officers in the Department of Atomic Energy 2023
GATE CSE 2023 Paper & Analysis - Memory Based
From GATE to Australia
DRDO Previous Year Papers
From Rank 4200 to 64: My Journey to Success in GATE CSE Exam
Subjects
All categories
General Aptitude
(2.5k)
Engineering Mathematics
(9.3k)
Digital Logic
(3.3k)
Programming and DS
(5.9k)
Programming
(3.9k)
DS
(1.9k)
Algorithms
(4.6k)
Theory of Computation
(6.7k)
Compiler Design
(2.3k)
Operating System
(5.0k)
Databases
(4.6k)
CO and Architecture
(3.8k)
Computer Networks
(4.6k)
Non GATE
(1.3k)
Others
(2.4k)
Admissions
(649)
Exam Queries
(842)
Tier 1 Placement Questions
(17)
Job Queries
(75)
Projects
(9)
Unknown Category
(853)
Recent Blog Comments
1200/1000 = 1.2
Aptitude- 1- there was a question, Like in a...
Suppose typing happens at 1 keystroke per second....
The algorithm for graph colouring was to pick...
@Aakash_Bhardwaj all the best bro . For your...
Twitter
WhatsApp
Facebook
Reddit
LinkedIn
Email
Link Copied!
Copy