User Tools

Site Tools


tech:tutorial:c_pointer_cheatsheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tech:tutorial:c_pointer_cheatsheet [2016/12/07 23:46]
rk4n3
tech:tutorial:c_pointer_cheatsheet [2016/12/07 23:52] (current)
rk4n3
Line 13: Line 13:
 int main( int argc, char *argv[]) { int main( int argc, char *argv[]) {
  
- int *pVal=0L; // Pointer to an int, address is 0 (null) + int iVal=2; // Regular ​int, set to 2 
- pVal = new int; // pVal now holds address of allocated int + int *pVal = &iVal; // Pointer to an int, holds address of iVal
- *pVal = 2; // The memory pVal points (an int) now has value 2 +
- int iVal = *pVal; // iVal set to value of int pVal points to+
  
  char cX='​E';​ //​ Regular char (1 byte) set to the character '​E'​  char cX='​E';​ //​ Regular char (1 byte) set to the character '​E'​
Line 35: Line 33:
  Info *pData = &​aData;​ //​ Pointer to an Info, holds address of aData  Info *pData = &​aData;​ //​ Pointer to an Info, holds address of aData
  aData.iMin = 0; // aData'​s iMin field is set to 0  aData.iMin = 0; // aData'​s iMin field is set to 0
- pData->​iMax = 4; // iMax of instance pData points to (aData) is now 4+ pData->​iMax = *pVal; // iMax of instance pData points to (aData) is now 2
  // String in sTxt ("​Ed"​) copied into aData'​s sName  // String in sTxt ("​Ed"​) copied into aData'​s sName
  strcpy( pData->​sName,​ sTxt);  strcpy( pData->​sName,​ sTxt);
tech/tutorial/c_pointer_cheatsheet.1481175985.txt.gz · Last modified: 2016/12/07 23:46 by rk4n3