-3

定数データへの非定数ポインタを介して意図的にデータを変更しようとしていたため、さまざまなエラーが表示されました。コンパイラが関数function_try(const * sPtr)を呼び出すときにエラーが表示されることを期待していますが、エラーが渡されて次のステップにエラーが表示されているようです...確認してガイドしてください...すべてに感謝します

 void function_try(const *sPtr);

 int main(void)
 {
     int y = 29;

     function_try(&y);

     printf("%d\n",y)

     system("PAUSE");

     return 0;

     }


 void function_try(const *sPtr)
 {
      *sPtr = 100;

     }
4

1 に答える 1

0

あなたはこのコードを実行することができます、そしてあなたが見たかったエラーを見ることができます

#include <stdio.h>
#include <stdlib.h>

void function_try(int *);

int main(void)
 {
     const int * y ;
     *y = 29;
     function_try(y);
     printf("%d\n",*y);
     return 0;

  }


 void function_try(int *sPtr)
 {
      *sPtr = 100;

 }

発生するエラーは

main.c:9:6: error: assignment of read-only location ‘*y’

エラーメッセージとともに、これらの警告も表示されます。

main.c:10:6: warning: passing argument 1 of ‘function_try’ discards ‘const’ qualifier from pointer target type [enabled by default]
main.c:4:6: note: expected ‘int *’ but argument is of type ‘const int *’
于 2013-03-06T06:53:39.880 に答える