C: Analysis of code

Discussion in 'C' started by negru, Mar 5, 2015.

  1. negru

    negru New Member

    Joined:
    Feb 13, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Could someone explain this code step by step:

    Code:
    #include <stdio.h>
    #define MAX 10
    int main()
    {
    char array[MAX][MAX], c = 0;
    int d = 1, x = 0, i, j;
    do scanf("%s", array[x]);
    while (array[x++][0] != '0');
    {
    float* pf;
    int xx, *pi = (int*)&array[0][7];
    xx = ((*pi) & 0x41000000);
    pf = (float*)&xx;
    printf("%5.2f\n", *pf);
    }
    for (c-=--x; c++&**array; d+=!(c<<x>0)) d<<=1;
    d -= c;
    for (i = 0; i < x;
    i==1?printf("%c ", array[i][x>>1]):i, ++i)
    for (j = 0; j <= x - i;
    printf("%c", array[i][j++]));
    printf("%x", d);
    return 0;
    }
    Example input:
    Code:
    programming language 0
    Output:
    Code:
    2.00
                           prolaa 6
    I tried debugging the program with Code Blocks, but didn't understand how it works.

    Thanks for replies.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What should this program be doing ?
     
  3. negru

    negru New Member

    Joined:
    Feb 13, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    This code is just for analysing. It is not doing anything.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Explain it? No, because it was clearly written by a complete idiot who has no regard for any kind of coding standards.

    Maybe it's an interview question designed to test *your* knowledge of C syntax.

    The program exhibits undefined behaviour because "programming" is more than 10 characters. So with this buffer overflow, anything that happens next is completely inexplicable.

    What is your analysis of the code? Are there any bits you don't understand?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice