第45课指针与数组

一、数组:

·存储在一块连续的内存空间中
·数组名就是这块连续内存空间的首地址


		#include <stdio.h>
		#include <stdlib.h>
		
		int main()
		{
			//数组名就是数组首元素地址
			double score[] = {98,87,65,43,76};
			printf("数组名:%p\t数组首元素地址:%p\n",score,&score[0]);
			return 0;
		}

		
		//运行结果****************************************************
		数组名:0060FEE8  数组首元素地址:0060FEE8
		
		Process returned 0 (0x0)   execution time : 2.052 s
		Press any key to continue.
		//运行结果****************************************************
		

		结论:
		
		ptr_score = &score[0]
		等价于
		ptr_score = score
		
		数组名就是数组首元素地址

二、指针的算术运算:

	·指针的递增和递减
	
		#include <stdio.h>
		#include <stdlib.h>
		
		int main()
		{
			int i;
			double score[] = {98,87,65,43,76};
			double* ptr_score = score;
			for(i = 0; i < 5; i++)
			{
			printf("%.2lf\n",*(ptr_score+i));
			}
			return 0;
		}
				
		//运行结果****************************************************
		98.00
		87.00
		65.00
		43.00
		76.00
		Process returned 0 (0x0)   execution time : 2.193 s
		Press any key to continue.
		//运行结果****************************************************	

猜你喜欢

转载自blog.csdn.net/cxd15194119481/article/details/85012040