Beginners Tutorial : The C-language :: Discussions
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.
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.
Replies
-
Ankita Katdare@simplycoder: Great initiative.
We are proud to have CEans like you! π -
Reya@simplycoder: Give us some debugging questions too.
-
TheVCan you explain this code ... . . .. !
#include
How the middle 'i' is being calculated..void main() { int i=1,a; a = ++i + (++i)++ + ++i ; printf("%d",a); } -
simplycoder@TheV:
Can you explain this code ... . . .. !
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.
Code:
#includevoid main() { int i=1,a; a = ++i + (++i)++ + ++i ; printf("%d",a); }
How the middle 'i' is being calculated..
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. -
TheV@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..
-
ReyaTheV: Is it running without any error?
-
simplycoder@TheV: Now rewrite yout code in Java if you can and post the answer.
See the sequence point ambiguity for the same. -
TheVFriends 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 ? -
simplycoderI 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
I dont really get you on this note. AFAIK, this is sequence point error.
14. Are you compiled this code in C ? Are you getting any 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. -
TheVBut 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.... -
simplycoder@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. -
Reyai got the output as 10.How come will the output will differ in Turboc3 and Devc?
-
H.AliHi 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 theprintf("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??
-
simplycoder@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. -
H.Aliplease explain the logic to print pascals triangle [using *]
-
simplycoderTo 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. -
monujattCode is not getting compiled in java.... giving error at (++i)++ π
-
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.simplycoderHello 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. -
simplycoder
You can refer the tutorial which I wrote on this forum,Engg.Deehi 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.
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 The C Programming Language nice book, and a must read for insights of the language.
If you have some doubt or stuck in analysis, post it down here. -
Engg.Dee
okk.............!simplycoderYou 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 The C Programming Language nice book, and a must read for insights of the language.
If you have some doubt or stuck in analysis, post it down here. -
Vishal Sharma
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!Can you explain this code ... . . .. !
Code:
#include
void main()
{
int i=1,a;
a = ++i + (++i)++ + ++i ;
printf("%d",a);
}
How the middle 'i' is being calculated..β -
Vishal Sharma
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!TheVCan you explain this code ... . . .. !
#include
How the middle 'i' is being calculated..void main() { int i=1,a; a = ++i + (++i)++ + ++i ; printf("%d",a); } -
Vishal SharmaOkay guys Here's a simple question!!
QUE:: Write a program to make a number HALF without using ' / '
Post your code snippets! π -
sulochana anandas my knowledge is concern if increment is applied three or more than three it increse twice in value.
-
sulochana anandam 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.
-
sulochana anand
can v try it as following sir?hahahaVishal0203Okay guys Here's a simple question!!
QUE:: Write a program to make a number HALF without using ' / '
Post your code snippets! π
int i=20;
printf(i>>1); -
Vishal Sharma
can v try it as following sir?hahaha
sir?? π¨ I'm just a 2nd year student π
int i=20;
printf(i>>1);
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?? π -
sulochana anand
yes u r writeVishal0203sir?? π¨ 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?? π -
123_neha
try this code for first inverted triangleH.Aliplease explain the logic to print pascals triangle [using *]
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
cout<<" "<<"*"<<" ";
}
cout<}
you can do the second one by simply reversing the above loops -
rahul69
This logic does not work on the floating point numbers..(i think..) . A much simpler and effective way is this:sulochana anandcan v try it as following sir?hahaha
int i=20;
printf(i>>1);
no=no*0.5;
π -
sulochana anandth
thanx i learned new thing.my math is not so good.rahul69This logic does not work on the floating point numbers..(i think..) . A much simpler and effective way is this:
no=no*0.5;
π -
Jeffrey Arulraj
Do you mean to say that you forgot your password for Win 7ohm's lawhow do I bypass a passworded computer running on windows 7 operating sysyem
Just remove the Cmos battery in the desktop that will reset all your passwords -
Brainyhello engineers, how are you all? Nice to meet you all here again.
-
Chinu1Thanks.. Please tell me about library function. And what the major difference between C and C++.
-
sulochana anand
i want to know how any number multiplied by 0.5 becomes half.sulochana anandth
thanx i learned new thing.my math is not so good. -
Jeffrey Arulraj
Hey there .5 = 5/10 = 1/2sulochana anandi want to know how any number multiplied by 0.5 becomes half.
Hope you got it
But this is not a place to start fresh ideas buddy try to shift your new questions to threads -
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!ConquerorHey 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 -
Jeffrey Arulraj
I am confused in your statement but the last part of your answer works the way you saysulochana anandthanx 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! -
suchismith roywhat 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 -
Vishal Sharma
in C, 0 stands for false.. and any other number means true..suchismith roywhat 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
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 -
SamiZzYSo this ques came in my paper, can anyone provide a ans with an explanation.
#include
{ 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);
} -
Pushpendra2911
on paper i solvedSamiZzYSo this ques came in my paper, can anyone provide a ans with an explanation.
#include
{ 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);
}
x = -8
y = 1
z = 0
let me know the answer -
SamiZzYThat's exactly the ans I came up with! Bt ppl were saying something like -6 1 0 . I dnt knw the real ans though.
-
rahul69
Ans should be x=6,y=1,z=1SamiZzYSo this ques came in my paper, can anyone provide a ans with an explanation.
#include
{ 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);
}
Initially x=y=z=10
then applying post(use then change) and pre(change then use) decrement, this answer is obtained.π -
SamiZzYAaaaaahhhhh damn! Bt thankyou.
-
SamiZzYActually 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.
-
Vishal Sharmagjhgj
-
Vishal SharmaI 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 -
Vishal Sharmasorry about "gjhgj" π I was unable to post π
-
Vishal Sharma
you can try tracing and adding a watch to the following code to understand the thingsSamiZzYActually 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.
#include
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; } -
SamiZzYHad to read 4th step again n again bt thnx man priceless explanation.
-
Vishal Sharma
I wanted you to do a little work over the calculation of (--x - x--) to understand how it works! Hope you understood it nowSamiZzYHad to read 4th step again n again bt thnx man priceless explanation. -
SamiZzYI think I do now thnx π
-
Jeffrey Arulraj
Try codecademy.comalicia32Hello 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.
there the C language is taught to you in your own pace That is really helpful
You are reading an archived discussion.
Related Posts
i'm a final year student of university of ilorin. i want project topic on web design
[video=youtube;lESZqCflB0o]https://www.youtube.com/watch?v=lESZqCflB0o&feature=relmfu[/video]
Gate Scorer above 99 percentile: Gate Scorer above 99 percentile have to apply for all IITβs and IISc with their interested specializations. They also have to apply for NITIE. If...
We've been denying Username Change requests. Those who want their username changed, please get in touch with me VIA PM as soon as possible with following information -
1. Username...
Centre for training an employment (CTE)- " A nodal agency for recruitment of various vacancies in different PSUs and semi-government organisation" has announced vacancies for Engineerβs in various streams (Electronics...