#include<iostream>usingnamespace std;intmain(){int arr[]={1,2,3,4,5,6,7,8,9,10};int* p = arr;
cout<<*p<<endl;for(int i =0;i<10;i++){
cout<<*p+i<<endl;}return0;}
2.指针函数
两个版本,直接对指针交换,或者对值交换,当然传入的都是地址
#include<iostream>usingnamespace std;//直接对指针交换//void swap1(int * a,int * b)//{// int * temp;// temp = a;// b = temp;// a = b;//}//或者对值交换voidswap2(int* a,int* b){int temp =*a;*a =*b;*b = temp;}intmain(){int a =10;int b =20;
cout<<"before swap!"<<endl;
cout<<a<<endl;
cout<<b<<endl;//swap1(a,b);//直接对指针交换swap2(&a,&b);//或者对值交换
cout<<"after swap!"<<endl;
cout<<a<<endl;
cout<<b<<endl;return0;}
c++ 基础知识-指针函数、数组1.指针数组#include <iostream> using namespace std; int main(){ int arr[] = {1,2,3,4,5,6,7,8,9,10}; int * p = arr; cout<<*p<<endl; for (int i = 0;i<10;i++) { cout<<*p+i<<endl; } ret