Search code examples
cstringvoid

Call a char pointer in the function


I saw the piece of the code. But do not know what the purpose is.

void a()
{
  static const char *string = "STRING";
  ...
  (void)string;  // <---- What the purpose of the line is?
  ...
}

Solution

  • (void) before a variable like that creates an empty expression and is used to silence warnings about a variable not being used by the program.

    In this specific case it would be better to simply comment out the variable declaration.