Sep 11, 2011

Difference between foo(void) and foo()


Consider these two function definitions
void foo(){ ... }
void foo(void){ ..... }
What is the difference between these two functions?

Hint: The answer depends whether this is C code or C++ code.

Sep 10, 2011

C code 32 bit vs 64 bit


The following C program segfaults of IA-64, but works fine on IA-32.

  int main()
      int* p;
      p = (int*)malloc(sizeof(int));
      *p = 10;
      return 0;
Update (Oct 30, 2011):
Wrong problem. Sorry for the trouble.

C++ Macro Concatenation

Problem: What is the output of the following C++ code?
  #include <stdio.h>
  #define f(a,b) a##b
  #define g(a)   #a
  #define h(a) g(a)

  int main()
          return 0;

Update (14 Sept 2011):

Solution posted in comments by Prathmesh Prabhu (CSE IITB 2010 Alumnus and Wisonsin Madison II-year Graduate Student)

Sep 4, 2011

Arrange in a Sequence

Asked to me by Amol Sahasrabudhe (IITB 2004 Alumnus, Worked at Morgan Stanley Quant Division, Deutsche Bank)

You are given 2n numbers ( 1 to n and 1 to n ). You have to arrange these numbers in a sequence such that between any two i`s , there exists exactly i-1 numbers. Is it possible for all n? If no, what are the values of n for which this is possible?

I have not been able to solve it. Sudhanshu Tungare (IITB 2008 EE Alumnus, Morgan Stanley) claims to have a solution. Cheers!

Update (November 1, 2011):
Part solution posted by Nishant Totla (CSE IITB Senior Undergraduate), Richie and Sarat in comments! Complete solution posted by Siddhant Agarwal (EE IITB Alumnus, CMI Grad student) in comments! Thanks a ton.

Fraction Brainteaser

Source: Sent to me by Gaurav Sinha Problem: Siddhant writes a Maths test and correctly answers 5 out of 6 Arithmetic questions and 20...