Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

What is the output?

c programming

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 negru

negru

    CC Newcomer

  • Member
  • PipPip
  • 17 posts

Posted 02 June 2016 - 12:56 PM

I tried to debug the following code "on paper" (without compiler/debugger),but it seems that is not possible because of the pointers.

#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:
programming languages 0
 
//Output:
 2.00
prolaa 6

Could someone explain this code?



#2 JonElias

JonElias

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 201 posts

Posted 10 June 2016 - 12:38 AM

but why? it seems like the program is working. what is it supossed to do?


"computers are useless they only give you answers" Pablo Picasso
And yes he was alive when the first programmable computer was made

#3 FossDustin

FossDustin

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 04 July 2016 - 04:42 AM

prog.cpp: In function 'int main()':
prog.cpp:20:13: error: expected primary-expression before '=' token
     for (c- = --x; c++ & **array; d+=!(c << x > 0)) 
             ^
prog.cpp: At global scope:
prog.cpp:32:1: error: 'programming' does not name a type
 programming languages 0
 ^


#4 FossDustin

FossDustin

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 04 July 2016 - 04:45 AM

It doesn't really work. Here's the outcome that I got.

 

cc1plus: warnings being treated as errors
In function 'int main()':
Line 16: warning: dereferencing type-punned pointer will break strict-aliasing rules
Line 20: error: expected primary-expression before '=' token
compilation terminated due to -Wfatal-errors.