Microsoft Interview Question
Software Engineer / DevelopersTeam: bing
Country: India
Interview Type: In-Person
I am posting very naive idea to get range of an integer..Hope it will work for all the architectures(16 Bit,32Bit,64Bit)..As we know integer uses 2s Complement..
#include <stdio.h>
int main()
{
register int i=1; // Using Register Storage Class In order to get faster result Still ,It is very Slow
while(1)
{
if(++i<0) {
printf("%d to %d",i,i-1 );
break;
}
}
return 0;
}
This might help.
#include<iostream>
#include<cstdlib>
using namespace std;
#define MY_SIZEOF(ele) ((unsigned char *)(&ele+1) - (unsigned char *)(&ele))
int main () {
int a = 6;
char b = 'c';
size_t size;
cout << MY_SIZEOF(a) << endl;
cout << MY_SIZEOF(b) << endl;
cout << MY_SIZEOF(size) << endl;
return 0;
}
In the current architectures int is 4 bytes long. signed int would be in the range -2^31 to 2^31.
- Anonymous March 26, 2012unsigned int would be in the range 0 to 2^32.