#include <iostream>
using namespace std;
#include <string>
#include "swap.h"
void bb( int arr1[], int len)//数组传入时特殊 传入的就是地址,所以不能做形参
{
for (int i=0; i < len - 1; i++)
{
for (int a = 0; a < len - 1 - i; a++)
{
if (arr1[a] >= arr1[a + 1])
{
int temp = arr1[a];
arr1[a] = arr1[a + 1];
arr1[a + 1] = temp;
}
}
}
for (int i = 0; i < len ; i++)
{
cout << arr1[i] ;
}
}
int main()
{
//for (int a = 0; a < 10; a++)
//{
// if (a % 2 == 0)
// {
// continue;
// break;//直接跳出 for 循环
// }
// else
// {
// cout << a << endl;
// }
//
//}
/*int arr[][3] = {1,2,3,4,5,6};
cout << arr[1][1] << endl;*/
/*int score[][3] = {100,100,100,90,90,90,80,80,80};
string stu[3] = {"A","B","C"};
for (int i = 0; i < sizeof(stu) / sizeof(stu[0]); i++)
{
cout << stu[i] << "的成绩是" << endl;
int sum = 0;
for (int a = 0; a < sizeof(score[0]) / sizeof(score[0][0]); a++)
{
sum += score[i][a];
}
cout << sum << endl;
}*/
/*int arr[2][2] = { 1,2,3,1 };
cout << arr << endl;
cout << &arr[0][0] << endl;*/
//int a = 10;
//int b = 20;
//swap(a,b);
头文件 .h
#pragma once
函数声明
源文件 .cpp
#include "头.h"
#include <iostream>
.......
/*int* p = (int*)1000;
cout << *p << endl;*/
//int a = 10;
//int b = 100;
//const int* p = &a;
*p = 500;//常量指针不能改内容
//p = &b;
//cout << *p << endl;
//int* const p1 = &a;
//*p1 = 500;
p1 = &a;//指针常量不行改地址
//cout << *p1 << endl;
int arr[5] = {1,9,5,7,6};
int len = 0;
len = sizeof(arr) / sizeof(arr[0]);
bb(arr, len);
cout << "------------------" << endl;
for (int i = 0; i < len; i++)
{
cout << arr[i] ;
}
}
review
最新推荐文章于 2024-11-09 20:38:27 发布