Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

initializing char pointers

I have a char pointer which would be used to store a string. It is used later in the program.

I have declared and initialized like this:

char * p = NULL;

I am just wondering if this is good practice. I'm using gcc 4.3.3.

like image 774
ant2009 Avatar asked Nov 02 '09 10:11

ant2009


1 Answers

Yes, it's good idea. Google Code Style recommends:

  1. To initialize all your variables even if you don't need them right now.
  2. Initialize pointers by NULL, int's by 0 and float's by 0.0 -- just for better readability.

    int i = 0;
    double x = 0.0;
    char* c = NULL;
    
like image 135
f0b0s Avatar answered Sep 20 '22 00:09

f0b0s