Tuesday, January 31, 2012

C/C++ Exercise: sizeof() and pointer

C/C++ Exercise: sizeof() and pointer
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: sizeof" << endl << endl;

 cout << "sizeof(int): " << sizeof(int) << endl;
 cout << "sizeof(char): " << sizeof(char) << endl;
 cout << endl;

 //Array
 char chArray[10];
 cout << "sizeof array: " << sizeof(chArray) << endl;
 cout << "sizeof a element in array: " << sizeof(chArray[0]) << endl;
 cout << "number of element in array: " << sizeof(chArray)/sizeof(chArray[0]) << endl;
 cout << endl;

 //pointer to int
 int i = 7;
 int* ptInt = &i;
 cout << "ptInt = " << ptInt << endl;
 cout << "*ptInt = " << *ptInt << endl;
 cout << "sizeof(ptInt): " << sizeof(ptInt) << endl;
 cout << "sizeof(*ptInt): " << sizeof(*ptInt) << endl;
 cout << endl;

 //pointer to char
 char* ptChar ("Hello World!");
 cout << "ptChar = " << ptChar << endl;
 cout << "*ptChar = " << *ptChar << endl;
 cout << "sizeof(ptchar): " << sizeof(ptChar) << endl;
 cout << "sizeof(*ptchar): " << sizeof(*ptChar) << endl;
 cout << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

Microsoft Xbox Live Coming To Droids And iPads

“While the Xbox Live experiences and games always work best on the Windows platform, we understand that some Xbox fans may be using other types of devices. To satisfy that need, we are working to extend a few of our Xbox experiences and titles to other platforms.” ~ A Microsoft spokesman stated.

Microsoft generates a significant amount of revenue from Xbox Live, its online gaming network. Xbox Live games are currently compatible only with one platform – Windows Phone. However, Microsoft is planning to bring Xbox Live games to other platforms like Apple’s iOS and Google‘s Android.

Source: http://www.forbes.com/sites/greatspeculations/2012/01/25/microsoft-xbox-live-coming-to-droids-and-ipads/

Monday, January 30, 2012

New standard of C++ - ISO/IEC 14882:2011

ISO/IEC 14882:2011, new standard of C++ programming language, revise ISO/IEC 14882:2003 and target to publish at 2012-02-28.

ISO/IEC 14882:2011 specifies requirements for implementations of the C++ programming language. The first such requirement is that they implement the language, and so ISO/IEC 14882:2011 also defines C++. Other requirements and relaxations of the first requirement appear at various places within ISO/IEC 14882:2011.

C++ is a general purpose programming language based on the C programming language as specified in ISO/IEC 9899:1999. In addition to the facilities provided by C, C++ provides additional data types, classes, templates, exceptions, namespaces, operator overloading, function name overloading, references, free store management operators, and additional library facilities.

ISO/IEC 14882:2011

Sunday, January 29, 2012

C/C++ Exercise: cout number in dec, hex, oct format using std::

C/C++ Exercise: cout number in dec, hex, oct format using std::
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: cout number in dec, hex, oct format using std::" << endl << endl;

 int number = 1024;
 cout << "dec: " << std::dec << number << endl;
 cout << "hex: " << std::hex << number << endl;
 cout << "oct: " << std::oct << number << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: Initializing pointer

C/C++ Exercise: Initializing pointer
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: Initializing pointer" << endl << endl;

 int number = 10;
 int *p_number = &number;
 cout << "pointer to address of another variable" << endl;
 cout << "p_number: " << p_number << endl;
 cout << "*p_number: " << *p_number << endl;
 cout << endl;

 int *p_nullptr = nullptr;
 cout << "pointer to nullptr" << endl;
 cout << "p_nullptr: " << p_nullptr << endl;
 //cout << "*p_nullptr: " << *p_nullptr << endl; // <- Invalid
 /* Will cause Unhandled exception at 0x003F13AE in Win32ConsoleApplication.exe:
  *  0xC0000005: Access violation reading location 0x00000000.
  */
 cout << endl;

 //Check if pointer point to anything
 if(p_number){
  cout << "p_number point to something" << endl;
 }else{
  cout << "p_number point to nothing" << endl;
 }
 cout << endl;

 if(p_nullptr){
  cout << "p_nullptr point to something" << endl;
 }else{
  cout << "p_nullptr point to nothing" << endl;
 }
 cout << endl;


 cout << endl;
 system("PAUSE");
 return 0;

}


nullptr represents a null pointer value. Use a null pointer value to indicate that an object handle, interior pointer, or native pointer type does not point to an object.

The nullptr keyword is equivalent to Nothing in Visual Basic and null in C#.

C/C++ Exercise: Initializing two-dimension array

#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: Initializing two-dimension array" << endl << endl;

 const int size_i = 3;
 const int size_j = 4;
 int a[size_i][size_j] = 
 {
  {0, 1, 2, 3},
  {10}
 };

 cout << endl;
 cout << "Accessed as two dimension array" << endl;
 for(int i = 0; i < size_i; i++){
  for(int j = 0; j < size_j; j++){
   cout << a[i][j] << " ";
  }
  cout << endl;
 }

 cout << endl;

 int *p = *a;
 cout << "Accessed by pointer" << endl;
 for(int i = 0; i < size_i * size_j; i++){
  cout << i << ":" << *(p + i) << " ";
 }
 cout << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: Initializing two-dimension array

C/C++ Exercise: Access two-dimension array by pointer

#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "Exercise: Access two-dimension array using pointer" << endl << endl;

 const int size_i = 3;
 const int size_j = 4;
 int a[size_i][size_j];
 

 //init array
 for(int i = 0; i < size_i; i++){
  for(int j = 0; j < size_j; j++){
   a[i][j] = i * 10 + j;
  }
 }

 cout << endl;
 cout << "Accessed as two dimension array" << endl;
 for(int i = 0; i < size_i; i++){
  for(int j = 0; j < size_j; j++){
   cout << a[i][j] << " ";
  }
  cout << endl;
 }

 cout << endl;

 int *p = *a;
 cout << "Accessed by pointer" << endl;
 for(int i = 0; i < size_i * size_j; i++){
  cout << i << ":" << *(p + i) << " ";
 }
 cout << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: Access two-dimension array by pointer