Find the answer to your Linux question:
Results 1 to 2 of 2
One day while pondering about C I came up with this program. Can you predict what the answer will be? Now run it, were you right? filename.c Code: #include <stdio.h> ...
  1. #1
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714

    C Brain Teaser For The New Year

    One day while pondering about C I came up with this program. Can you predict what the answer will be? Now run it, were you right?


    filename.c
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char**argv)
    {
    	unsigned long *iptr = (unsigned long*)0;/*pointer equals 0*/
    	unsigned long ans = (unsigned long)(iptr + 1);/*add 1 to the pointer*/
    	
    	fprintf(stdout, "and the answer is->%lu\n", ans);/*whats the answer?*/
    	exit(EXIT_SUCCESS);
    }
    gcc filename.c -Wall -ansi -pedantic -o filename
    Make mine Arch Linux

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    I was wrong

    EDIT:
    But now I know why
    Last edited by GNU-Fan; 01-02-2010 at 08:46 AM.
    Debian GNU/Linux -- You know you want it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •