-
@simplycoder: Great initiative.
We are proud to have CEans like you! 👍
Are you sure? This action cannot be undone.
-
Reya
Member •
Aug 20, 2011
@simplycoder: Give us some debugging questions too.
Are you sure? This action cannot be undone.
-
TheV
Member •
Aug 20, 2011
Can you explain this code ... . . .. !
#include<stdio.h>
void main()
{
int i=1,a;
a = ++i + (++i)++ + ++i ;
printf("%d",a);
}
How the middle 'i' is being calculated..
Are you sure? This action cannot be undone.
-
@TheV:
Can you explain this code ... . . .. !
Code:
#include<stdio.h> void main() { int i=1,a; a = ++i + (++i)++ + ++i ; printf("%d",a); }
How the middle 'i' is being calculated..
I dont think you compiler is going to like this, I have not written the code as yet, but then I do think that post increment is going to make some troubles with this program.
As a thumb rule, modifying any statement more than once without a sequence point will lead to undefined results in C.
in your case you have modified i multiple times without a sequence point, this will cause
sequence point ambiguity.
The best thing is, you can write your code in some other language except for C++ say in a Java, find out your result and let us know if they are same or not.
Are you sure? This action cannot be undone.
-
TheV
Member •
Aug 20, 2011
@simplycoder... I have compiled this code in Turbo C++ and it's giving me 14 as output...but I can't make it out the actual calculating procedure..
Are you sure? This action cannot be undone.
-
Reya
Member •
Aug 20, 2011
TheV: Is it running without any error?
Are you sure? This action cannot be undone.
-
@TheV: Now rewrite yout code in Java if you can and post the answer.
See the sequence point ambiguity for the same.
Are you sure? This action cannot be undone.
-
TheV
Member •
Aug 20, 2011
Friends have you compiled the code ,,,,,, I have compiled in both Turbo C++ and borland C++ . I am getting the same
answer as 14 . .. Are you people got the same answer or having any error...??
@simplycoder: I have compiled the same code after writing in java ... and I am getting 4 error.. But I am not concern about java compiler
As java and C compilers are different so the result is different but I have written this code in C and I am getting answer as
14. Are you compiled this code in C ? Are you getting any error ?
Are you sure? This action cannot be undone.
-
I am getting the post-increment errors as I pointed out.
As java and C compilers are different so the result is different but I have written this code in C and I am getting answer as
14. Are you compiled this code in C ? Are you getting any error ?
I dont really get you on this note. AFAIK, this is sequence point error.
You can try the expression : a = ++i + ++i + ++i; in java and c. This wont give you any error, but surely will give you different answers.
Are you sure? This action cannot be undone.
-
TheV
Member •
Aug 21, 2011
But I am not getting any error.....
Originally posted by: simplycoder.
You can try the expression : a = ++i + ++i + ++i; in java and c. This wont give you any error, but surely will give you different answers.
That what I wanted to say you in my above lines....
In java It is giving me ---- 9
but in C ------------------12
In C I understood the concept..It first increases the pre-increment of ' i ' and then placed to evaluate the expression..(Correct me if wrong)
Can you explain me what is concept in java...? How 9 output is been shown in java....
Are you sure? This action cannot be undone.
-
@TheV: surprisingly, for me in on my devC++, its 10 from C program.
this is the sequence point ambiguity.
java works in the same way in case of increment.
but then for C its just sequence point ambiguity. check for google on the same for sequence point ambiguity.
Are you sure? This action cannot be undone.
-
Reya
Member •
Aug 21, 2011
i got the output as 10.How come will the output will differ in Turboc3 and Devc?
Are you sure? This action cannot be undone.
-
H.Ali
Member •
Sep 7, 2011
Hi simply coder ...... 😀
your Tutorials are really Helpful.. and thanking you for your Efforts....
have a question regarding the sample program given in 16 th tutorial(Menu Driven program)...
>> in your program the
printf("ANSWER :: %lf\n",answer);
is placed out side the Switch , its ok when when the case 1 to 4 occurs 😀
but when the Default case is executed , it also prints the answer
!
i think it will be better if the printf is placed inside each cases ,(but then we have to type it 4 times 😔 )
any other suggestion??
Are you sure? This action cannot be undone.
-
@H.Ali: Yeah, you are correct. My Bad.
I think we have to place printf you are correct. We should print it 4 times. That is very easy and nothing new is to be learnt.
thanks for pointing it out.
Are you sure? This action cannot be undone.
-
H.Ali
Member •
Sep 20, 2011
please explain the logic to print pascals triangle [using *]
Are you sure? This action cannot be undone.
-
To program any pattern, just make a table like this.
[TABLE="class: grid"]
[TR]
[TD]Row.no[/TD]
[TD]Stars[/TD]
[TD]Blanks[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]4[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]5[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]n[/TD]
[TD]n[/TD]
[TD]n-stars[/TD]
[/TR]
[/TABLE]
By using this logic, you can print the stars.
Make sure you print blanks first and then stars.
Are you sure? This action cannot be undone.
-
Code is not getting compiled in java.... giving error at (++i)++ 😀
Are you sure? This action cannot be undone.
-
simplycoder
Hello everyone, I am simplycoder and welcome to C-programing discussions.
In this thread, you can post your questions and I shall try to answer them to best of my knowledge.
I prefer the questions which are parallel to the thread dedicated to tutorials,but I shall answer any question which I think I can.
So just shoot the questions, some one would answer your questions sooner or later as this forum has a lot of good programers.
hi simply coder......i am from production engg. and i will have to face and campus drive in coming month. Tcs is coming for campus..they want us to have a fundamental knowledge of a language...can u help me to learn the basic of c.
Are you sure? This action cannot be undone.
-
Engg.Dee
hi simply coder......i am from production engg. and i will have to face and campus drive in coming month. Tcs is coming for campus..they want us to have a fundamental knowledge of a language...can u help me to learn the basic of c.
You can refer the tutorial which I wrote on this forum,
Pointers is an important topic left uncovered in tutorial.
Hopefully soon I shall get some time to start writing from where I left.
For book I suggest <a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" target="_blank" rel="nofollow noopener noreferrer">The C Programming Language</a> nice book, and a must read for insights of the language.
If you have some doubt or stuck in analysis, post it down here.
Are you sure? This action cannot be undone.
-
simplycoder
You can refer the tutorial which I wrote on this forum,
Pointers is an important topic left uncovered in tutorial.
Hopefully soon I shall get some time to start writing from where I left.
For book I suggest <a href="https://en.wikipedia.org/wiki/The_C_Programming_Language" target="_blank" rel="nofollow noopener noreferrer">The C Programming Language</a> nice book, and a must read for insights of the language.
If you have some doubt or stuck in analysis, post it down here.
okk.............!
Are you sure? This action cannot be undone.
-
Can you explain this code ... . . .. !
Code:
#include<stdio.h>
void main()
{
int i=1,a;
a = ++i + (++i)++ + ++i ;
printf("%d",a);
}
How the middle 'i' is being calculated..
the i modification statements are undefined. Different compilers may produce different outputs which cannot be judged. The pre-, -post increments are not supposed to be used in this way since the main reason for using the increments is controlling the loops. The above snippet causes ambiguity or confusion to the compiler as the same value is being incremented in several ways. hence, different compilers produce different outputs!
Are you sure? This action cannot be undone.
-
TheV
Can you explain this code ... . . .. !
#include<stdio.h>
void main()
{
int i=1,a;
a = ++i + (++i)++ + ++i ;
printf("%d",a);
}
How the middle 'i' is being calculated..
the i modification statements are undefined. Different compilers may produce different outputs which cannot be judged. The pre-, -post increments are not supposed to be used in this way since the main reason for using the increments is controlling the loops. The above snippet causes ambiguity or confusion to the compiler as the same value is being incremented in several ways. hence, different compilers produce different outputs!
Are you sure? This action cannot be undone.
-
Okay guys Here's a simple question!!
QUE:: Write a program to make a number HALF without using ' / '
Post your code snippets! 😀
Are you sure? This action cannot be undone.
-
as my knowledge is concern if increment is applied three or more than three it increse twice in value.
Are you sure? This action cannot be undone.
-
am also agree that increment nd decrement op are used in loop.so no need more discussion over it.diffrent compiler may give diffrent result.its also true.
Are you sure? This action cannot be undone.
-
Vishal0203
Okay guys Here's a simple question!!
QUE:: Write a program to make a number HALF without using ' / '
Post your code snippets! 😀
can v try it as following sir?hahaha
int i=20;
printf(i>>1);
Are you sure? This action cannot be undone.
-
can v try it as following sir?hahaha
int i=20;
printf(i>>1);
sir?? 😨 I'm just a 2nd year student 😖
by the way, your code just needs a quoted %d in printf() statement, everything is fine after that. haha 😁
Any other ways to do it?? 😏
Are you sure? This action cannot be undone.
-
Vishal0203
sir?? 😨 I'm just a 2nd year student 😖
by the way, your code just needs a quoted %d in printf() statement, everything is fine after that. haha 😁
Any other ways to do it?? 😏
yes u r write
Are you sure? This action cannot be undone.
-
H.Ali
please explain the logic to print pascals triangle [using *]
try this code for first inverted triangle
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
cout<<" "<<"*"<<" ";
}
cout<<endl;
}
you can do the second one by simply reversing the above loops
Are you sure? This action cannot be undone.
-
sulochana anand
can v try it as following sir?hahaha
int i=20;
printf(i>>1);
This logic does not work on the floating point numbers..(i think..) . A much simpler and effective way is this:
no=no*0.5;
😎
Are you sure? This action cannot be undone.
-
th
rahul69
This logic does not work on the floating point numbers..(i think..) . A much simpler and effective way is this:
no=no*0.5;
😎
thanx i learned new thing.my math is not so good.
Are you sure? This action cannot be undone.
-
ohm's law
how do I bypass a passworded computer running on windows 7 operating sysyem
Do you mean to say that you forgot your password for Win 7
Just remove the Cmos battery in the desktop that will reset all your passwords
Are you sure? This action cannot be undone.
-
hello engineers, how are you all? Nice to meet you all here again.
Are you sure? This action cannot be undone.
-
Thanks.. Please tell me about library function. And what the major difference between C and C++.
Are you sure? This action cannot be undone.
-
sulochana anand
th
thanx i learned new thing.my math is not so good.
i want to know how any number multiplied by 0.5 becomes half.
Are you sure? This action cannot be undone.
-
sulochana anand
i want to know how any number multiplied by 0.5 becomes half.
Hey there .5 = 5/10 = 1/2
Hope you got it
But this is not a place to start fresh ideas buddy try to shift your new questions to threads
Are you sure? This action cannot be undone.
-
Conqueror
Hey there .5 = 5/10 = 1/2
Hope you got it
But this is not a place to start fresh ideas buddy try to shift your new questions to threads
thanx i got it.mens if v want to make half 13.then 13*0.5=6.5.0.5=5/10=1/2*13=6.5.right!
Are you sure? This action cannot be undone.
-
sulochana anand
thanx i got it.mens if v want to make half 13.then 13*0.5=6.5.0.5=5/10=1/2*13=6.5.right!
I am confused in your statement but the last part of your answer works the way you say
Are you sure? This action cannot be undone.
-
what will be the output and why
main()
{
if(2,1,0)
printf("yes");
else
printf("no");
the output comes as no..as i have compiled it ...plz expalin me how
Are you sure? This action cannot be undone.
-
suchismith roy
what will be the output and why
main()
{
if(2,1,0)
printf("yes");
else
printf("no");
the output comes as no..as i have compiled it ...plz expalin me how
in C, 0 stands for false.. and any other number means true..
so whenever the condition is true, if block statement will be executed, else the else part..
you've give 3 numbers 2,1,0
since 0 stands for false, and o/p is no;
if you just write 2,1,4,5,6,7....(non zero, non-negetive)
then o/p will be yes
Are you sure? This action cannot be undone.
-
So this ques came in my paper, can anyone provide a ans with an explanation.
#include<stdio.h>
{ int x=10,y,z;
z=y=x;
y-=--x;
z-=x--;
x-=--x - x--;
printf("x=%d y=%d z=%d",x,y,z);
}
Are you sure? This action cannot be undone.
-
SamiZzY
So this ques came in my paper, can anyone provide a ans with an explanation.
#include<stdio.h>
{ int x=10,y,z;
z=y=x;
y-=--x;
z-=x--;
x-=--x - x--;
printf("x=%d y=%d z=%d",x,y,z);
}
on paper i solved
x = -8
y = 1
z = 0
let me know the answer
Are you sure? This action cannot be undone.
-
That's exactly the ans I came up with! Bt ppl were saying something like -6 1 0 . I dnt knw the real ans though.
Are you sure? This action cannot be undone.
-
SamiZzY
So this ques came in my paper, can anyone provide a ans with an explanation.
#include<stdio.h>
{ int x=10,y,z;
z=y=x;
y-=--x;
z-=x--;
x-=--x - x--;
printf("x=%d y=%d z=%d",x,y,z);
}
Ans should be
x=6,y=1,z=1
Initially x=y=z=10
then applying post(use then change) and pre(change then use) decrement, this answer is obtained.😒
Are you sure? This action cannot be undone.
-
Aaaaaahhhhh damn! Bt thankyou.
Are you sure? This action cannot be undone.
-
Actually I was hoping if someone could explain it step by step . I knw abt the post and pre increment operators but again and again I arrive at the wrong ans.
Are you sure? This action cannot be undone.
-
gjhgj
Are you sure? This action cannot be undone.
-
I think calculating the value of z and y is not a big deal, still I'll explain..
after 1st line x=y=z => x = 10, y = 10, z = 10
second step is y -= --x viz. equal to y = y - --x i.e. y = 10 - 9 (according to what rahul69 said, pre-decrement is done first and then the value is assigned)
so, y = 1 and present values of x = 9 , y = 1 , z = 10
in third step, z = z - x-- i.e. z = 10 - 9 (since post decrement, x value is assigned first and then x is decremented)
so, z = 1 present values are x = 8 , y = 1 , z = 1
forth step, x = x - (--x - x--) i.e. x = x - (7 - 7) (hope you understood why i've written 7 - 7)
i've not written the value of x in above statement because after the calculation of
(--x - x--) {bracketed part is calculated first because of the precedence rule} the value of x changes to 6
so, x = 6
therefore, your answer is x = 6, y = 1, z = 1
Are you sure? This action cannot be undone.
-
sorry about "gjhgj" 😛 I was unable to post 😒
Are you sure? This action cannot be undone.
-
SamiZzY
Actually I was hoping if someone could explain it step by step . I knw abt the post and pre increment operators but again and again I arrive at the wrong ans.
you can try tracing and adding a watch to the following code to understand the things
#include<stdio.h>
int main()
{
int x=10,y,z;
z=y=x;
y-=--x;
z-=x--;
int a =--x; //calculation of x broken into 3 parts
int b =x--;
int c = x - (a - b);
printf("x=%d y=%d z=%d",x,y,z);
return 0;
}
Are you sure? This action cannot be undone.
-
Had to read 4th step again n again bt thnx man priceless explanation.
Are you sure? This action cannot be undone.
-
SamiZzY
Had to read 4th step again n again bt thnx man priceless explanation.
I wanted you to do a little work over the calculation of (--x - x--) to understand how it works! Hope you understood it now
Are you sure? This action cannot be undone.
-
I think I do now thnx 😁
Are you sure? This action cannot be undone.
-
alicia32
Hello and thanks for the information. I need to know from where i can download tutorials on PDF format or in video format. I am learning C and looking for some additional help. I have find this forum very helpful that is why i am asking for help.
Try codecademy.com
there the C language is taught to you in your own pace That is really helpful
Are you sure? This action cannot be undone.