KartalKaan's blog

By KartalKaan, 11 years ago, In English

Hello! I've just started using stringstream's but I've encountered a problem. Why does this code print 0 ?

#include<iostream>
#include<sstream>
using namespace std;
int main()
{
	stringstream ss;
	int i;
	ss<<0;
	ss>>i;
	ss<<1;
	cout<<ss.str()<<endl;
	return 0;
}

Thanks in advance.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By KartalKaan, 11 years ago, In English

Hello everyone! I have two codes, they print different things but I don't know why. The first one is :

#include <stdio.h>
int main()
{
   int p[6]={1,2,3,4,5,6};
   int *q=(int *)(&p+1);
   printf("%ld\n",q-p);
   return 0;
}

And the second one :

#include <stdio.h>
int main()
{
   int p[6]={1,2,3,4,5,6};
   int *q=(int *)(p+1);
   printf("%ld\n",q-p);
   return 0;
}

First code prints 6, whereas the second one prints 1. The only difference is that the first code has an ampersand before "p+1". Do you know the reason? Thanks.

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it