掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
ポインター渡し (ID:55503)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
#include <iostream.h> #include <stdlib.h> void Display( void ); int Input( void ); void Arrange( int *passed ); const int buffer = 256; // main function int main () { static int pass[1]={0}; int *address = &pass[0]; Display(); pass[1] = Input(); cout << "\t *The address in the main function " << &pass[1] << endl; Arrange( address ); return 0; } //////////////////////////////////////////////////////////////// void Display( void ) { cout << "\t ******************************" << endl; cout << "\t Please enter numbers 9 times." << endl; cout << "\t ******************************" << endl; return; } /////////////////////////////////////////////////////// int Input( void ) { static int num[9]={0,0,0,0,0,0,0,0,0}; int *point; point = num; // Insert the head address of num for ( int i = 0 ; i < 9 ; ){ cout << "\t"; if ( cin >> num[i] ){ i++; system("cls"); cout << "\t Please enter again." << endl; }else{ cin.clear(); cin.ignore( buffer, '\n'); system("cls"); cout << "\t You did not entered number." << endl; cout << "\t Please enter number." << endl; } } return ( *point ); } //////////////////////////////////////////////////////// void Arrange( int *passed ) { cout << "\t Arrange start." << endl; int results[10]={0,0,0,0,0,0,0,0,0,0}; cout << "\t *The Head address is " << &passed << endl; for( int i = 0 ; i < 9 ; i++ ){ for ( int j = 10 ; i < 9 ; j-- ){ results[j] = passed[i]; } } cout << "\t Before values" << "\t\t" << "After values" << endl; for ( int m = 0 ; m < 9 ; m++ ){ cout << "\t ________________________________" << endl; cout << m+1 << "\t" << &passed[m] << "\t\t\t" << results[m] << endl; } }
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.