C/C++ Beginner's Guide and Post Basic Questions here

nims11

BIOS Terminator
[/COLOR]Output Problem

cout<<a++<<a++<<b--<<--b<<++b<<--b;

I m havin problem in assumin the ouput of such syntax. Usullly i get unexpected results. Any reason for tht and way to encounter it?

let a=1 and b=2 before this 'cout' statement.
then here is what happens when "cout<<a++<<a++<<b--<<--b<<++b<<--b;" is executed.

a++
output a; a+=1;
a is now 2, b is now 2;
output status : 1

a++
output a; a+=1;
a is now 3, b is now 2;
output status : 12

b--
output b; b-=1;
a is now 3, b is now 1;
output status : 122

--b
b-=1;output b;
a is now 3, b is now 0;
output status : 1220

++b
b+=1;output b;
a is now 3, b is now 1;
output status : 12201

--b
b-=1;output b;
a is now 3, b is now -1;
output status : 122010


Final Output- 122010.
 
OP
Liverpool_fan

Liverpool_fan

Sami Hyypiä, LFC legend
^^It depends on the compiler IMO.

This. It falls under the domain what we call "Undefined Behaviour".

Ron: Try compiling your C++ code with g++ -Wall flag and see the warning. ;)

As for global variables.
c++ - Are global variables bad? - Stack Overflow
Global Variables Are Bad
 

mitraark

Decrepit
Any software all in one package i can use to write and compile C [ GCC ] >?? DevC++ or something ??? Something which can be installed on machines without Internet connection [ unlike MinGW which is downloading files ]

---------- Post added at 04:01 PM ---------- Previous post was at 03:49 PM ----------

MinGW is working great , will i be able to install it in Windows 7 6 Bit PC without Internet connection ?
 

skeletor

Chosen of the Omnissiah
I am a student and can't understand why the author of this post is telling us not to use turbo C++ thats the compiler they teach us in school and college:shock:
Let me put this straightforwardly. Indians are idiots. Not even Pakistanis use Turbo C++.

Teachers are not willing to move on. The curriculum makers are sleeping. et cetera.

---------- Post added at 05:07 PM ---------- Previous post was at 05:03 PM ----------

Any software all in one package i can use to write and compile C [ GCC ] >?? DevC++ or something ??? Something which can be installed on machines without Internet connection [ unlike MinGW which is downloading files ]

---------- Post added at 04:01 PM ---------- Previous post was at 03:49 PM ----------

MinGW is working great , will i be able to install it in Windows 7 6 Bit PC without Internet connection ?

Try this out: CodeLite IDE LiteEditor/Download

Here is the direct link: *sourceforge.net/projects/codelite/...9/codelite-2.9.0.4684-mingw4.4.1.exe/download
 

skeletor

Chosen of the Omnissiah
^^Okay, so whats widely used in development now?
Anything with which you are comfortable with.

Eclipse, Netbeans and Microsoft Visual C++ are excellent. But many of their features are unnecessary if you are only into basic programming.

Dev C++ comes with an old version of MiniGW by default.
 

vickybat

I am the night...I am...
^^ eclipse and netbeans are for java only right. I'm interested only in c++. So Microsoft Visual C++ will be a good choice right?
 

skeletor

Chosen of the Omnissiah
No, you can use Netbeans and Eclipse for C/C++ programming too. Microsoft Visual C++ is a good choice, no doubt.
 

nims11

BIOS Terminator
Hey guyz i have a problem...
There is an easy question at SPOJ whose answer is a set of many numbers which i have to output to stdout. the time limit is 6 sec. i used C++. The algo does the processing of these numbers in less than 2 seconds in worst case. But outputting these numbers is causing the program to exceed the time limit!! any suggestions?
 

Neuron

Electronic.
Instead of printing each of the number with separate output commands,use a single command to output a group of numbers at the same time.

Run following codes,the second one will be faster.

for(i=0;i<100000;i++)
printf("%d ",i);

for(i=0,j=1,k=2;i<100000;i+=3,j+=3,k+=3)
printf(" %d %d %d",i,j,k);
 

nims11

BIOS Terminator
sorry for replying late...
thanx it works but i had to use a series of 10 "%d" to make it significantly faster...

Most confusing C Code.... - Fun Enclave
 

RBX

In the zone
Re: Post your C/C++ Programs Here

How will this be evaluated in C and C++ ?

printf("%d",sizeof('A'));
 
Re: Post your C/C++ Programs Here

Code:
Code:

#include <STDIO.H>  
 using namespace std;   
int main(char *args, int argc) 
{ 
  printf("%d float\n",sizeof(float));  
  printf("%d int\n",sizeof(int)); 
  printf("%d char\n",sizeof(char));  
  printf("%d long\n",sizeof(long));  
  return 0; 
} 

Output:

4 float
4 int
1 char  //your answer
4 long
 
Top Bottom