-
Virtual Method
Base class has some virtual method and derived class has a method with the same name. if we initialize the base class pointer with derived object, calling of that virtual method will result in which method being called?
-
-
Which expression always return true? Which always return false?
expression if (a=0) always return false expression if (a=1) always return true
-
What is the difference between NULL and NUL?
NULL is a macro defined in <stddef.h> for the null pointer. NUL is the name of the first character in the ASCII character set. It corresponds to a zero value. There’s no standard macro NUL in C, but some people like to define it. The digit 0 corresponds to a value of 80, decimal. Don’t confuse the digit 0 with the value of ‘’ (NUL)! NULL can be defined as ((void*)0), NUL as ‘’.
-
}
">Vii)7. main(){ int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m);}
0 0 1 3 1Explanation :Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0 (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination-...
-
How do you redirect a standard stream?
Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; it can be redirected to a file or printer port. Similarly, your program’s input (stdin) can come from a file rather than the keyboard. In DOS, this task is accomplished using the redirection characters,...
-
When would you use a pointer to a function?
Pointers to functions are interesting when you pass them to other functions. A function that takes function pointers says, in effect, “Part of what I do can be customized. Give me a pointer to a function, and I’ll call it when that part of the job needs to be done. That function can do its part for me.” This is known as a “callback.” It’s used a lot in graphical user interface libraries, in which...
-
How do you print only part of a string?
/* Use printf() to print the first 11 characters of source_str. */ printf(“First 11 characters: ‘%11.11s’n”, source_str);
-
How can type-insensitive macros be created?
A type-insensitive macro is a macro that performs the same basic operation on different data types. This task can be accomplished by using the concatenation operator to create a call to a type-sensitive function based on the parameter passed to the macro. The following program provides an example: #include <stdio.h> #define SORT(data_type) sort_ ## data_type void sort_int(int** i); void sort_long(long**...
-
-
-
-
printf(" %d", sizeof(u.a));
// printf("%d", sizeof(u.a[4].i));
}
">Union u{ union u { int i; int j; }a[10]; int b[10];}u;main(){ printf("n%d", sizeof(u)); printf(" %d", sizeof(u.a));// printf("%d", sizeof(u.a[4].i));}
A) None of the AboveB) 1, 100, 1C) 40, 4, 4D) 4, 4, 4Explanation: 20, 200, error for 3rd printf
-
-
Given the values of two nodes in a *binary search tree*, write a cprogram to find the lowest common ancestor. You may assume that bothvalues already exist in the tree.The function prototype is as follows:int FindLowestCommonAncestor(node* root,int value1,int value) 20 / 8 22 / 4 12 / 10 14I/P : 4 and 14O/P : 8(Here the common ancestors of 4 and 14, are {8,20}. Of {8,20}, the lowest one is 8).
One of the solution can be to find out postorder traversal taking each node one by one. This postorder function should return true if both the values (v1 & v2) are found in the postorder traversal of the given node. NOTE: The given tree is a BST.... think over it......
-
-
-
-
-
Execute Shell Command
How will you execute shell command without using system command in C-language? Write a program to execute ls -l and redirect the output to a file, without using system command ?
C Interview Questions
Ans