Skip to main content
fixed typo that changed the meaning of my sentence!
Source Link
curiouskiwi
  • 18.7k
  • 2
  • 18
  • 43

int * is a pointer to an int, so you'll get two errors there:

error: incompatible integer to pointer conversion initializing
      'int *' with an expression of type 'int' [-Werror,-Wint-conversion]
int *pkk = 5646;
     ^     ~~~~
ptr.c:6:18: error: format specifies type 'int' but the argument has type 'int *'
      [-Werror,-Wformat]
  printf("%d\n", pkk);
          ~~     ^~~

The first is saying that you cancan't initialize a pointer with an integer value. The second is saying that you can't print a pointer type using the "%d" format specifier, as that is for printing an integer.

Your char * example works fine because of how C defines a char pointer.

Pointers are covered in Weeks 4 and 5. Have you already completed those?

int * is a pointer to an int, so you'll get two errors there:

error: incompatible integer to pointer conversion initializing
      'int *' with an expression of type 'int' [-Werror,-Wint-conversion]
int *pkk = 5646;
     ^     ~~~~
ptr.c:6:18: error: format specifies type 'int' but the argument has type 'int *'
      [-Werror,-Wformat]
  printf("%d\n", pkk);
          ~~     ^~~

The first is saying that you can initialize a pointer with an integer value. The second is saying that you can't print a pointer type using the "%d" format specifier, as that is for printing an integer.

Your char * example works fine because of how C defines a char pointer.

Pointers are covered in Weeks 4 and 5. Have you already completed those?

int * is a pointer to an int, so you'll get two errors there:

error: incompatible integer to pointer conversion initializing
      'int *' with an expression of type 'int' [-Werror,-Wint-conversion]
int *pkk = 5646;
     ^     ~~~~
ptr.c:6:18: error: format specifies type 'int' but the argument has type 'int *'
      [-Werror,-Wformat]
  printf("%d\n", pkk);
          ~~     ^~~

The first is saying that you can't initialize a pointer with an integer value. The second is saying that you can't print a pointer type using the "%d" format specifier, as that is for printing an integer.

Your char * example works fine because of how C defines a char pointer.

Pointers are covered in Weeks 4 and 5. Have you already completed those?

Source Link
curiouskiwi
  • 18.7k
  • 2
  • 18
  • 43

int * is a pointer to an int, so you'll get two errors there:

error: incompatible integer to pointer conversion initializing
      'int *' with an expression of type 'int' [-Werror,-Wint-conversion]
int *pkk = 5646;
     ^     ~~~~
ptr.c:6:18: error: format specifies type 'int' but the argument has type 'int *'
      [-Werror,-Wformat]
  printf("%d\n", pkk);
          ~~     ^~~

The first is saying that you can initialize a pointer with an integer value. The second is saying that you can't print a pointer type using the "%d" format specifier, as that is for printing an integer.

Your char * example works fine because of how C defines a char pointer.

Pointers are covered in Weeks 4 and 5. Have you already completed those?