Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the value of an uninitialized string in c? [duplicate]

Tags:

c

Possible Duplicate:
initial value of int array in C

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
    char name[10];
    printf("%s\n", name);
    return 0;
}

What value does an uninitialized string in C hold ? Does the compiler automatically allocate a storage of size 10 and fill it with garbage values ? What basically happens on writing the above code ?

like image 745
Nikunj Banka Avatar asked Feb 05 '13 07:02

Nikunj Banka


1 Answers

10 bytes are allocated on the stack, that's all. Their value is left as is, that means it is what ever had been written to such 10 bytes before having been allocated.

like image 171
alk Avatar answered Oct 16 '22 15:10

alk