Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2646 of 3366
2K+ Views
The POSIX stands for Portable Operating System which was developed by IEEE (Institute of Electrical and Electronics Engineers). This is UNIX based operating system that is used for both system calls and library functions. The semaphores are used in the process of multithreading and synchronization. For eg. file sharing and memory management. It can be named or unnamed. Multithreading is the process of executing multiple tasks in the same instance of time while synchronization is used to control the thread to work in a sequential manner. It is important for data security. Using Semaphores in C language To use ... Read More
1K+ Views
The self-destructing code is a type of program that can delete itself. It automatically executes the program and then removes the executable file once the execution is done. In this article, we will learn how to write self-destructing code for a C program. Write a Self Destructing Code in C++ You can write a self-destructing program that deletes its own executable file after it finishes running by using the remove() function. The remove() function is a built-in function from the C standard library () that deletes the specified file from the file system. To delete the program's own executable file, ... Read More
334 Views
In C++11, the lambda was introduced. Lambdas are basically a part of code, that can be nested inside other function call statements. By combining lambda expressions with the auto keyword, they can be used later.In C++14, these lambda expressions are improved. Here we can get the generalized lambda. For example, if we want to create a lambda, that can add integers, add numbers, also concatenate strings, then we have to use this generalized lambda.Syntax of the lambda expression is looking like this:[](auto x, auto y) { return x + y; }Let us see one example to get the better idea.Example#include ... Read More
4K+ Views
To print random numbers within a range, we will have two input variables where we need to set the maximum and minimum values. Using these two values, we can display a random value within the specified range. Example Following is the input-output statement to understand the range of a random number: Input: min = 4, max = 14 Output: 8, 10, 7 Explanation: Any numeric value between 4 and 14 can be displayed in the specified range. Generate Random Number Within a Range Using rand() with Modulus The rand() function generates the random number while modulus operator return ... Read More
2K+ Views
To create high precision timer we can use the chrono library. This library has high resolution clock. This can count in nanoseconds.In this program we will see the execution time in nanoseconds. We will take the time value at first, then another time value at the last, then find the difference to get elapsed time. Here we are using blank loop to pause the effect for sometimes.Example#include #include typedef std::chrono::high_resolution_clock Clock; main() { auto start_time = Clock::now(); for(int i = 0; i
1K+ Views
The segmentation error is one of the runtime error, that is caused because of the memory access violation, like accessing invalid array index, pointing some restricted address etc. In this article, we will see how to detect this type of error using the GDB tool.Let us see the code and respective steps to locate the error.Example#include main() { int* ptr = NULL; *ptr = 1; //trying to access unknown memory location printf("%p", ptr); }Compile the code using ‘gcc –g program_name.c’, and run using ‘./a.out’Outputsoumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$ ./a.out Segmentation fault (core dumped)The segmentation error occurred.Write ‘gdb ./a.out core’soumyadeep@soumyadeep-VirtualBox:~/Cpp_progs$ gdb ... Read More
233 Views
This mbrtowc() function is used to convert multibyte sequence to wide character string. This returns the length of the multibyte characters in byte. The syntax is like below.mbrtowc (wchar_t* wc, const char* s, size_t max, mbstate_t* ps)The arguments are −wc is the pointer which points where the resulting wide character will be stored.s is the pointer to multibyte character string as inputmax is the maximum number of bytes in s, that can be examinedps is pointing to the conversion state, when interpreting multibyte string.Example#include using namespace std; void display(const char* s) { mbstate_t ps = mbstate_t(); // initial ... Read More
9K+ Views
The getopt() is one of the built-in C function that are used for taking the command line options. The syntax of this function is like below −getopt(int argc, char *const argv[], const char *optstring)The opstring is a list of characters. Each of them representing a single character option.This function returns many values. These are like below −If the option takes a value, then that value will be pointed by optarg.It will return -1, when no more options to procesReturns ‘?’ to show that this is an unrecognized option, it stores it to optopt.Sometimes some options need some value, If the ... Read More
13K+ Views
In C/C++, an error occurs due to an invalid operation performed by the user. The error normally stops the program execution until it is fixed. So, the error should be removed before compilation and execution. Types of Error in C/C++ Following is the list of errors occur in C/C++ programming: Syntax Error Run-Time Error Linker Error Logical Error Semantic Error In this article, we will see the implementation of error in C/C++ programs. Syntax Error The syntax error ... Read More
2K+ Views
In C, sorting arrays is a common task, and one of the functions that help with sorting is qsort(). To sort the array, qsort() needs a comparator function to decide how to compare two elements. Without this function, qsort() wouldn't know how to order the data. The task here is to understand how to write and use a comparator function with qsort() to sort arrays in different orders. For example, consider this array of integers: arr[] = {5, 2, 9, 1, 5, 6} We want to sort this array in ascending or descending order. The comparator function tells qsort() ... Read More