/*
* main.cpp
*
* Created on: Sep 12, 2013
* Author: user
*/
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <climits>
using std::cout;
using std::cin;
using std::endl;
using std::hex;
using std::dec;
int main( int argc, char* argv[] )
{
// a, operation ( |, &, etc ) for short types
short a = 0x7fff, b = 0x7fff;
int c = 0x7fffffff, d = 0x7fffffff;
cout << " Size of short " << sizeof( a ) << endl;
cout << " Sizes of int " << sizeof( c ) << endl;
if( a + b < b ) cout << " short integer overflow " << endl;
else cout << "no short integer overflow" << endl;
if( c + d < d ) cout << " integer overflow " << endl;
else cout << "no integer overflow" << endl;
a = 0x8000; b = 0x7fff;
unsigned int z = a | b;
cout << hex << " operator | " << z << endl;
a = -1; b = 0x1010;
z = a & b;
cout << hex << " operator & " << "a : " << a << ", b: " << b << ", z : " << z << endl;
// b, unsigned of greater size
int integer = INT_MAX;
unsigned int uinteger = integer + 1;
cout << endl;
cout << " int to uint ( bigger ) " << endl;
cout << dec << "integer ( " << integer << " ) to unsigned integer ( " << uinteger << " ) " << endl;
cout << endl;
// c, using -1 and UNIT_MAX
char divisionMinus = -1;
char divisionPlus = -1;
cout << endl;
cout << "* c, to divide using -1 and UNIT_MAX " << endl;
cout << "( minus ) -1 division = " << divisionMinus / UINT_MAX << endl;;
cout << "( plus ) 1 division = " << divisionPlus / UINT_MAX << endl;;
cout << endl;
// d, expanding unsigned integer to signed of the same size (big values)
uinteger = UINT_MAX;
integer = uinteger;
cout << endl;
cout << " uint to int ( the same ) " << endl;
cout << dec << "unsigned integer ( " << uinteger << " ) to integer ( " << integer << " ) of the same size" << endl;
cout << endl;
// e, expanding unsigned integer to signed of the bigger size (big values)
uinteger = UINT_MAX;
integer = uinteger + 1;
cout << endl;
cout << " uint to int ( the bigger )" << endl;
cout << dec << "unsigned integer ( " << uinteger << " ) to integer ( " << integer << " ) of the bigger size" << endl;
cout << endl;
return 0;
}
/*
* main.cpp
*
* Created on: Sep 12, 2013
* Author: user
*/
#include <stdio.h>
#include <string.h>
char *str = " Test string111111";
int val = 10;
int main(int argc, char **argv)
{
char buf[ 12 ];
strncpy( buf, argv[ 1 ], sizeof( buf ) );
buf[ sizeof( buf ) - 1 ] = 0;
printf( " Address of str == %p\n", &str[0] );
printf( " Address of val == %p\n", &val );
printf( " val == %d\n", val );
printf( buf );
printf("\n");
printf( " val == %d\n", val );
return 0;
}
application of automate tool analysis.