これは私の最初の質問です。お会いできてうれしい! Linux上ですべては私が期待どおりに動作しながら、CWindows上のgccが変数に特定の値を割り当てるのはなぜですか?
gcc -o C:\test.exe test.c
(gccのバージョン2015年6月27日)を使用してWindows上でコンパイル
#include <stdio.h>
int main(){
int choice;
printf("\nSize of 'choice' %d\n", sizeof(choice));
printf("Size of 'int' %d\n", sizeof(int));
printf("Value of 'choice %d\n", choice);
return 0;
}
で書かれたこのコードは、これらの値
Size of 'choice' 4
Size of 'int' 4
Value of 'choice 2
を返す理由を誰かが説明してもらえこれらの値を返す
Size of 'choice' 4
Size of 'int' 4
Value of 'choice 0
私は何が欠けていますか?
ありがとうございます。
未定義の動作に異なりますので、そのデフォルト値が定義されていない初期化されていないランダムな値が含まれ、それが何」です失われた –
初期化されていない変数へのアクセスは未定義の動作です(何か起こります) –
http://stackoverflow.com/documentation/c/364/undefined-behavior/1472/use-of-an-uninitialized-variable#t=20161018123252455759 – Abhineet