Category Archives: C/C++

Command Injection Vulnerability and Mitigation

Command injection is basically injection of operating system commands to be executed through a web-app. The purpose of the command injection attack is to inject and execute commands specified by the attacker in the vulnerable application. In situation like this, the application, which executes unwanted system commands, is like a pseudo system shell, and the… Read More »

Descending order in Map and Multimap of C++ STL

We have discussed map in C++ STL and multimap in C++ STL. The default behavior of these data structures is to store elements in ascending order. How to ensure reverse order or descending order when inserting elements in map and multimap. The idea is to greater function when an instance of map/multimap. Descending order in… Read More »

Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)

Binary search is an important component in competitive programming or any algorithmic competition, having knowledge of shorthand functions reduces the time to code them. This searching only works when container is sorted. Related functions are discussed below. 1.binary_search(start_ptr, end_ptr, num) : This function returns boolean true if the element is present in the container, else… Read More »

Output of C Program | Set 29

Question 1 How many times main() will get called? Answer : Infinite loop Description : There is no condition in the main() to stop the recursive calling of the main() hence it will be called infinite no of times. Question 2 Guess the output of the following program : Answer : x and y are… Read More »

new and delete operators in C++ for dynamic memory

Dynamic memory allocation in C/C++ refers to performing memory allocation manually by programmer. Dynamically allocated memory is allocated on Heap and non-static and local variables get memory allocated on Stack (Refer Memory Layout C Programs for details). What are applications? One use of dynamically allocated memory is to allocate memory of variable size which is… Read More »

How does Duff’s Device work?

Duff’s device is a trick to express loop unrolling directly in C or C++ without extra code to treat the leftover partial loop.The trick is to use a switch statement where all but one of the cases labels are in the middle of a while loop. Further, all cases fall through to the end of… Read More »