Tuesday, April 27, 2010

References

int i;
int& r = i;              // r refers to i
r = 1;                    // the value of i becomes 1
int* p = &r;           // p points to i
int& rr = r;           // rr refers to what r refers to, that is, to i
int (&rg)(int) = g;  // rg refers to the function g
rg(i);                    //calls function g
int a[3];
int (&ra)[3] = a;    // ra refers to the array a
ra[1] = i;              // modifies a[1]

Wild Card characters

A wildcard character is a character that may be substituted for any of a defined subset of all possible characters. In computer (software) technology, a wildcard character can be used to substitute for any other character or characters in a string.
For ex:
*.jpg
matches any text which end with .jpg. You can also specify brackets with characters, as in:

*.[ch]pp
matches any text which ends in .cpp or .hpp. Altogether very similar to regular expressions.
The * means match zero or more of anything in wildcards. As we learned, we do this is regular expression with the punctuation mark and the * quantifier. This gives:

.*
Also remember to convert any punctuation marks from wildcards to be backslashified.
The ? means match any character but do match something. This is exactly what the punctuation mark does.

Friday, April 23, 2010

awesum link(Threads concept for dummies)

http://www.codestyle.org/java/faq-Threads.shtml

awesum link(Threads concept for dummies)

http://www.codestyle.org/java/faq-Threads.shtml

Tuesday, April 20, 2010

basic function definitions

int i - declares an integer
int *pi - declares a pointer pi to an integer
int f() - declares a function f with no input parameters and returns an integer
int *fpi(int) - declares a function fpi taking an integer argument and returning a pointer to an
integer
int (*pif)(const char*, const char*) - a pointer pif to a function taking two pointers to const characters
and returning an integer
int (*fpif(int))(int) - a function fpif taking an integer as an argument and returning a pointer to a
function that takes integer arguments and returns an integer

Tuesday, April 13, 2010

Tuesday, April 6, 2010

  1. Usage of pointers and their fundamentals in C?
    Pointers are mainly used for the dynamic allocation of memory. A pointer contains the address of the variable. They are also helpful in passing parameters to subroutines.
     void* sample;Using the above example’s definition and assigning the pointer to void to the address of an integer variable is perfectly correct.sample=&i; where i is an int.Using the above example to define the pointer to void and assign the pointer to void to the address of a float variable as below is also perfectly correct.sample=&f; where f is a floatPointer to void, or a void pointer, is a special type of pointer that has a great facility of pointing to any data type.NULL pointer is a type of pointer of any data type and generally takes a value as zero. This is, however, not mandatory. This denotes that NULL pointer does not point to any valid memory address. It is important to note that a NULL pointer is different from a pointer that is not initialized.
  2. What is the difference between structures and unions in C?Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
    Structure enables us treat a number of different variables stored at different in memory.
    Since all of them are referring to the same location in memory the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent from each other.
  3. Basic concepts about data structures like trees, linked lists, circular lists, queues, arrays?The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations.

Some interview questions with answers

  1. Usage of pointers and their fundamentals in C?
    Pointers are mainly used for the dynamic allocation of memory. A pointer contains the address of the variable. They are also helpful in passing parameters to subroutines.
     void* sample;
    Using the above example’s definition and assigning the pointer to void to the address of an integer variable is perfectly correct.
    sample=&i; where i is an int.
    Using the above example to define the pointer to void and assign the pointer to void to the address of a float variable as below is also perfectly correct.
    sample=&f; where f is a float
    Pointer to void, or a void pointer, is a special type of pointer that has a great facility of pointing to any data type.NULL pointer is a type of pointer of any data type and generally takes a value as zero. This is, however, not mandatory. This denotes that NULL pointer does not point to any valid memory address. It is important to note that a NULL pointer is different from a pointer that is not initialized.

  2. What is the difference between structures and unions in C?
    Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members.
    Structure enables us treat a number of different variables stored at different in memory.
    Since all of them are referring to the same location in memory the modification of one of the elements will affect the value of all of them. We cannot store different values in them independent from each other.
  3. Basic concepts about data structures like trees, linked lists, circular lists, queues, arrays?
    The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations.