Knowledge is Power.

  • Who you are ?

    Working on machines without understanding them ? Then you should be here..

  • Where you are ?

    Geographical location should not become a barrier to Share our knowledge.

  • What do you do ?

    Puzzles and Interview question are intended to be discussed here.

    Wednesday, February 24, 2010

    Q1.)

    #include
    #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
    int array[] = {23,34,12,17,204,99,16};

    int main()
    {
    signed int d;
    printf("Total Elements in the array are => %d\n",TOTAL_ELEMENTS);
    for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
    printf("%d\n",array[d+1]);
    printf("Did u see the output..");
    return 0;
    }


    Q 2.) File1.c 1 int arr[80]; File2.c extern int *arr;
    int main()
    {
    arr[1] = 100;
    return 0;
    }
    what should be the output..


    Q 3.) #include
    int main()
    {
    int a=1;
    switch(a)
    { int b=20;
    case 1: printf("b is %d\n",b);
    break;
    default:printf("b is %d\n",b);
    break;
    }
    return 0;
    }



    Q.4)
    #include
    #include
    void Error(char* s)
    {
    printf(s);
    return;
    }

    int main()
    {
    int *p;
    p = (int*)malloc(sizeof(int));
    if(!p)
    {
    Error("memory error");
    Error("Quitting....\n");
    exit(1);
    }
    else
    {
    /*some stuff to use p*/
    }
    free(p);
    return 0;
    }

    Find potential problem with the error function.. a security concern..






    Q 5.)
    Easy..
    #include
    int main()
    {
    char c;
    scanf("%c",&c);
    printf("%c\n",c);
    scanf(" %c",&c);//see space before %c
    printf("%c\n",c);

    return 0;
    }

    why this runs perfect..
    but fails in this program..

    #include
    int main()
    {
    char c;
    scanf("%c",&c);
    printf("%c\n",c);
    scanf("%c",&c);//no space this time..
    printf("%c\n",c);

    return 0;
    }

    Even though we know that white spaces are ignored..
    which include space, newline and tab..
    so why the second time output is not desired..

    0 comments:

    Post a Comment