pointers.cpp

来自「Since the field of object oriented progr」· C++ 代码 · 共 36 行

CPP
36
字号
                              // Chapter 3 - Program 1 - POINTERS.CPP
#include <iostream.h>

int main()
{
int   *pt_int;
float *pt_float;
int   pig = 7, dog = 27;
float x = 1.2345, y = 32.14;
void *general;

   pt_int = &pig;
   *pt_int += dog;
   cout << "Pig now has the value of " << *pt_int << "\n";
   general = pt_int;

   pt_float = &x;
   y += 5 * (*pt_float);
   cout << "y now has the value of " << y << "\n";
   general = pt_float;

   const char *name1 = "John";    // Value cannot be changed
   char *const name2 = "John";    // Pointer cannot be changed

   return 0;
}




// Result of execution
//
// Pig now has the value of 34
// y now has the value of 38.3125

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?