Cプログラミング
 Computer >> コンピューター >  >> プログラミング >> Cプログラミング

C / C ++での%pと%xの違い


ここでは、CまたはC ++での%pと%xの違いを確認します。 %pはポインター値を出力するために使用され、%xは16進値を出力するために使用されます。ただし、ポインタは%uまたは%xを使用して表示することもできます。 %pと%xを使用して値を出力する場合、大きな違いは感じられません。気付くことができる唯一の違いは、%pはいくつかの先行ゼロを出力しますが、%xは出力しないことです。

#include<stdio.h>
main() {
   int x = 59;
   printf("Value using %%p: %p\n", x);
   printf("Value using %%x: %x\n", x);
}

出力

Value using %p: 000000000000003B
Value using %x: 3b

  1. C / C++の#include<filename>と#includefilenameの違いは?

    2つの形式の違いは、プリプロセッサが含まれるファイルを検索する場所にあります。 #include プリプロセッサは、実装に依存する方法で検索し、コンパイラによって事前に指定されたディレクトリを検索します。このメソッドは通常、標準ライブラリヘッダーファイルをインクルードするために使用されます。 #include filename プリプロセッサは、ディレクティブを含むファイルと同じディレクトリを検索します。これが失敗すると、#includeフォームのように動作し始めます。このメソッドは通常、独自のヘッダーファイルをインクルードするために使用されます。

  2. C /C++でのconstint*、const int * const、およびint const *の違いは?

    上記の記号は、次のことを意味します- int* - Pointer to int. This one is pretty obvious. int const * - Pointer to const int. int * const - Const pointer to int int const * const - Const pointer to const int また、-にも注意してください const int * And int const * are the same. const int * const And int const * const are the same.