Wednesday, 6 January 2016

Instantiating the inner class is same as normal class instantiation. Follow the sample code for better understanding.
#include<iostream>



int a;



struct test

{

   int a;

   struct inner

   {

      void callme()

      {

         a=0;

         printf("\n  :: %d ", a );

         printf("\n  :: %d ", ::a );

      }

   };

};



int main()

{

   test::inner obj;

   obj.callme();

   return 0;

}

Tuesday, 5 January 2016


Enums which is declared inside the class should be accessed with help of class name followed by scope resolution operator.

Syntax:
ClassName::EnumValue

#include<iostream>

struct test

{
   enum op

   {

      mytrue,
      myfalse,

   };

};

int main()

{
   printf("\n  :: %d ", test::myfalse );
   return 0;

}

Monday, 4 January 2016



#include<iostream>

pthread_mutex_t g_mutex;

void* threadproc(void *p)

{
   printf("\n Going to lock...");

   pthread_mutex_lock(&g_mutex);

   int ret=pthread_mutex_timedlock(&g_mutex,&l_timeSpec);

   printf("\n  :: %d ", ret );

   pthread_mutex_timedlock(&g_mutex,&l_timeSpec);

   printf("\n  :: %u ", g_mutex );

   return NULL;
}



void* threadproc2(void *p)

{
   struct timespec l_timeSpec;

   memset(&l_timeSpec,0,sizeof(l_timeSpec));

   l_timeSpec.tv_sec=50;

   printf("\n  :: %u ", g_mutex );

   pthread_mutex_lock(&g_mutex);

   int ret=pthread_mutex_timedlock(&g_mutex,&l_timeSpec);

   printf("\n  :: %d ", ret );

   pthread_mutex_timedlock(&g_mutex,&l_timeSpec);

   printf("\n  :: %u ", g_mutex );

   return NULL;
}
int main()
{
   pthread_t l_thread,l_thread2;

   pthread_mutex_init(&g_mutex,NULL);

   pthread_create(&l_thread,NULL,threadproc,NULL);

   pthread_create(&l_thread2,NULL,threadproc,NULL);

   pthread_join(l_thread,NULL);

   pthread_join(l_thread2,NULL);
   return 0;
}

Sunday, 3 January 2016


Floating point numbers are represented in the machine based on the IEEE 754 standard.
One of the limitation represented by the IEEE floating point standard is if we store the number "33554431" in the machine, while retrieving the number it is given as
"33554432"

This is one of the IEEE floating point exception or floating point error


Sample Program for floating point error:


#include<iostream>

int myFunction()
{
   return 0;
}

int main()
{
   float f=33554431;
   printf("\n  :: %f ", f );
   return 0;
}


Output:
  :: 33554432.000000