c - How to check first char of a char pointer variable wihtout making any changes to the variable itself -


for example, want check whether first character of char pointer variable a. dont want char pointer variable changed @ all, want check first character.

the first character @ start of characters pointed pointer can checked against value. in fact, work if pointer points single character:

 int main()  {    char *a;     = malloc(1);    *a = 'a';    if('a' == *a) { printf("a first character\n");    return 0;  } 

alternatively, accomplish same thing treating array:

 int main()  {    char a[]="a string of characters";     if('a' == a[0]) { printf("a first character\n");    return 0;  } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -