Sum the digits of a number in single statement
Write a single statement (simple or compound) which can compute sum of digits of an unsigned int.
comma operator
Comma in C and C++ comes in two flavours As separator (used to separate parameters in a function call) As operator (rarely used) The two flavors are as different as it can be. Lets discuss them one by one:
Ages of three children
A lady has 3 daughters, A man visited their house and asked the ages of her three daughters. The lady started giving him clues: Lady: Product of their ages (ages of her 3 daughters) is 72. Man did some calculations and says: The clue is insufficient to determine the ages. Lady: Ok, let me give […]
Difference between malloc, calloc, free and realloc functions
Functions malloc, calloc, realloc and free are used to allocate /deallocate memory on heap in C/C++ language. These functions should be used with great caution to avoid memory leaks and dangling pointers. How are these functions different (or similar)?
Print edge nodes (boundary nodes) of a Binary Tree
Given a Binary Tree. Write code to print the boundary nodes of the Tree. For example, if the Binary tree is __30__ / \ / \ 20 40 / \ / \ 10 25 35 50 / \ \ / 5 15 28 41 The output should be: 30 20 10 5 15 28 35 […]
Singleton class with public constructor
The Singleton Design Pattern requires Constructors to be defined as private member of the class (Default constructor, Copy constructors and Overloaded Assignment operator should all be defined private in case of C++). This pattern is explained here.. If the programming language you are using does not allow you to define the constructor as private or protected […]
Big and Little Endian
Little and big endian are two ways of storing multibyte data ( int, float, etc) in memory. – If machine is big endian, then first byte of binary representation of multi-byte data is stored first. – If machine is little endian, then last byte of binary representation of multi-byte data is stored first.
Add two integers without using arithmetic operator
Write a function that accepts two unsigned int and return sum of these two integers. The function should not use any arithmetic operator (mayuse bitwise operators only).
Print character occurring maximum number of times in a string
Write a function which will print the character coming maximum number of times in a given String. For example: Input String: ritambhara Output: a Because character ‘a‘ appears 3 times in the String.
Longest substring of unique characters
Given a String in which characters may be repeating. Find the length of longest substring of where all characters are unique (non-repeating). For Example: If the String is “RITAMBHARA” Length of Longest substring with unique characters = 7 (“RITAMBH”)