Programming Tips 2
 

 Programming Tips 1

 Programming Tips 3

   Programming Tips 4

 


C Tip


What's wrong with the following declaration:

char* ptr1, ptr2 ;

I get errors when I try to use ptr2 as a pointer.

Ans:char * applies only to ptr1 and not to ptr2. Hence ptr1 is getting declared as a char pointer, whereas, ptr2 is being declared merely as a char. This can be rectified in two ways :
  • char *ptr1, *ptr2 ;

  • typedef char* CHARPTR ; CHARPTR ptr1, ptr2 ;



C++ Tip


void f ( float n, int i = 10 ) ;

void f ( float a ) ;

void main( )

{

f ( 12.6 ) ;

}

void f ( float n, int i )

{

}

void f ( float n )

{

}

The above program results in an error (ambiguous call) since without the default argument the two functions have arguments that are matching in number, order and type.