Pages

Wednesday, December 14, 2011

A simple C program

Let's talk about simplicity. And let's look at a simple C program today. Why not, every day we deal with complex problem, so let's talk about a simple C program now. Here is the program;

main()

{

    char *p1="name";

    char *p2;

    p2=(char*)malloc(20);

    memset (p2, 0, 20);

    while(*p2++ = *p1++);

    printf("%s\n", p2);

}

Well, what does this program do. This is the topic of today's blog.

Ans:

Looks like this program output's the string name , but that's not true.

What do you think about this program?

Write your comments about it.