Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

258
Visualizações
What ! (char*) means in C

I was looking at an example and I saw this:

char *str;

/* ... */

if (!str || !*str) {
    return str;
}

Does it mean it's empty or something?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

str is a char pointer. ! negates it. Basically, !str will evaluate to true (1) when str == NULL.

The second part is saying, (if str points to something) evaluate to true (1) if the first character is a null char ('\0') - meaning it's an empty string.

Note:
*str dereferences the pointer and retrieves the first character. This is the same as doing str[0].

over 4 years ago · Santiago Trujillo Relatório

0

!str means that there is no memory allocated to str. !*str means that str points to an empty string.

over 4 years ago · Santiago Trujillo Relatório

0

Before asking you can do small tests.

#include <stdio.h>

int main()
{
    char *str = "test";
    printf("%d\n",*str);
    printf("%c\n",*str); // str[0]
    printf("%d\n",str);
    if (!str || !*str)
    {
        printf("%s",str);
    }

    return 0;
}

meaning of ! is negation. Except 0 every value is true for if condition. Here, str and *str return values that are not 0. So, you can make an inference.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda