C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

Home » C++ programming language

Warning and Error Messages in C++

Here, we will learn some of the warnings and errors in C/C++, while compiling and executing a C++ program, we found some error and warning messages, some of them are we will discuss here.

C/C++ programming languages are very popular and most used programming languages in the world, writing programs and executing are very easy but sometimes, while compiling or executing the program, we get some messages (warnings/errors) and program does not compile/execute successfully.

Here, we are discussing some of the common warning/error messages:

  1. Null pointer assignment
  2. Non-portable pointer conversion
  3. Suspicious pointer conversion

1) Null pointer assignment

It is a runtime error. It can occur due to some reasons, one of the main reasons is "null pointer assignment, it generally occurs when pointer has NULL value and it shows the error, when we access such kind of pointer or illegal memory location (a memory space which is assigned to operating system or other process.) through our program.

Value of NULL is 0, it is a macro. While accessing NULL assigned pointer that means we are trying to access the 0th location of the memory. And it will generate an error because 0th address is used (may be used) for operating related processes. Which is not allowed to access by the program/user.

2) Non-portable pointer conversion

It’s a type of warning and it occurs when we try to access a pointer variable without using strike (*) character (for dereferencing pointer).

When we use a pointer in non-pointer context, it is legal but non-portable. This type of code may work, but it can be failed at any stage.

3) Suspicious pointer conversion

It’s a type of warning, and it occurred when we try to assign the address of different type of variable in the different type of pointer. We can say if the type of variable (whose address is going to be assigned to the pointer) and pointer are not same.

Consider the program:

#include <stdio.h>

int main()
	float *ptr1, val=3.14;
	char *ptr2;

	ptr1 = &val;
	ptr2 = &val;

	return 0;

Above program generate warning suspicious pointer conversion after compilation. Because we are trying to store the address of val, that is float into a character pointer.