Skip to main content


  • In C language, sizeof( ) is an operator. Though it looks like a function, it is an unary operator.

  • To know the IP address(es) of a URL/website, nslookup can be used at the shell/command prompt (cmd.exe). It works on both types of operating systems i.e. Linux/Windows.

                                     For example : nslookup 

  • In ISO C, you can define main either to take no arguments, or to take two arguments that represent the command line arguments to the program, like this:

int main (int argc, char *argv[])
 Other platform-dependent formats are also allowed by the C and C++ standards; for example, Unix (though not POSIX.1) and Microsoft Visual C++ have a third argument giving the program’s environment, otherwise accessible through getenv in stdlib.h:

  • In C, function parameters are always passed by value. Pass-by-reference is simulated in C by explicitly passing pointer values.

  • A large proportion of programming languages are bootstrapped, including BASIC, C, Pascal, Factor, Haskell, Modula-2, Oberon, OCaml, Common Lisp, Scheme, and more.

Example for inline functions
inline int max(int a, int b)
  if (a > b)
    return a;
    return b;

a = max (x, y); 
  This is now equivalent to 
  if (x > y)
    a = x;
    a = y;
Example for variable length arrays
float read_and_process(int n)
    float   vals[n];
    for (int i = 0; i < n; i++)
        vals[i] = read_val();
    return process(vals, n);

  • “Pointer arithmetic and array indexing [that] are equivalent in C, pointers and arrays are different”– Wayne Throop

  • To uniquely construct a Binary Tree, Inorder together with either Postorder or Preorder must be given (See this for details). However, either Postorder or Preorder traversal is sufficient to uniquely construct a Binary Search Tree. To construct Binary Search tree, we can get Inorder traversal by sorting the given Preorder or Postorder traversal. So we have the required two traversals and can construct the Binary Search Tree.

  • Enumeration constants (enum values) are always of type int in C, whereas they are distinct types in C++ and may have size different from that of int.

  • Following relationship holds in any n-ary tree in which every node has either 0 or n children.

                                                              L = (n-1)*I + 1

                     Where L is the number of leaf nodes and I is the number of internal nodes.


The tree is n-ary tree. Assume it has T total nodes, which is sum of internal nodes (I) and leaf nodes (L). A tree with T total nodes will have (T – 1) edges or branches.

In other words, since the tree is n-ary tree, each internal node will have n branches contributing total of n*I internal branches. Therefore we have the following relations from the above explanations,

n*I = T – 1
L + I = T

From the above two equations, it is easy to prove that L = (n – 1) * I + 1.

  • In C, struct keyword must be used for declaring structure variables, but it is optional in C++.

For example, following program gives error in C and works in C++.
struct node {
   int x;
   node *next; // Error in C, struct must be there. Works in C++
int main()
   node a;  // Error in C, struct must be there. Works in C++
And following program works in both C and C++.
struct node {
   int x;
   struct node *next;  // Works in both C and C++
int main()
   struct node a;  // Works in both C and C++

  • const Behaviour in C and C++

In C, the const qualified identifiers will have external linkage, where as in C++ it will have internal linkage. For example,
In C++, the following statement
float const interest_rate = 9.25;
is implicitly defined as
static float const interest_rate = 9.25;
i.e. the scope of interest_rate is limited to the block in which it is defined.
In C, the above statement will have external linkage when defined at file scope, i.e. it will be visible outside the current translation unit (source file).
The internal linkage of const qualified variables have some advantages in C++. 

  • .In C, a structure cannot have static members, but in C++ a structure can have static members.

For example, following program causes compilation error in C, but works in C++.

struct test {
  static int i;  // Error in C, but works in C++.

int main()
  struct test t;    
  return 0;

  • Predict the output of following program.

#include <stdio.h>
int main() 
   int x = 012;
   printf("%d",  x);
   return 0;
The program prints 10. Putting a 0 before an integer constant makes it an octal number and putting 0x (or 0X) makes it a hexadecimal number. It is easy to put a 0 by accident, or as a habit. The mistake is very common with beginners.


Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …

Hackerrank > SQL > Basic Select

01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
02-Select by ID
Given a City table, whose fields are described as