Problem : 1

#include <stdio.h>
#include <string.h>
int main() 
    char a [] = "12345";
    int i = strlen (a);
    printf ("here is 3 %d\n",++i);

// What's the output ? [Do not execute / run]
// post your answer as a comment
// Source :

29 thoughts on “Problem : 1

  1. char a [] = “12345”;
    we haven’t defined the size of the array in declaration. This enables us to initialize values and the compiler will allocate necessary spaces.

    int i = strlen (a);
    The length of the array is determined by the number of character elements. strlen () returns the length of a string. here, i = 5

    printf (“here is 3 %d\n”,++i);
    the value of ‘i’ is pre-incremented. that is, the value of ‘i’ will be incremented before printing.

    and, “here is 3” is concatenated with the output to fuddle u. 😛

    Correct Output : here is 3 6

  2. here is 36″Becouse 1 2 3 4 5 ” and ++i ,string start from 0 to array define so 1=0,2=1,3=2…….++i increment the value which occopy by null charactor .null charactor value here 5 and after increment 6 now we have 6 and printf defination has already 3 ,so combination is 36

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s