Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C Articles
Page 86 of 96
How to execute zombie and orphan process in a single C program?
In this section we will see how to execute zombie process and orphan process in a single program in C. Before going to the main discussion, let us see what are the zombie process and orphan process. Zombie Processes A zombie process is a process whose execution is completed but it still has an entry in the process table. Zombie processes usually occur for child processes, as the parent process still needs to read its child's exit status. Once this is done using the wait system call, the zombie process is eliminated from the process table. This is ...
Read MorePrinting Heart Pattern in C
In this program we will see how to print heart shaped pattern in C. The heart shape pattern consists of two rounded peaks at the top and an inverted triangle forming the base. *** *** ***** ***** *********** ********* ******* ***** *** * Now if we analyze this pattern, we can find different sections. The base of the heart is an inverted triangle; ...
Read Morefork() in C
In this section we will see what is the fork system call in C. This fork system call is used to create a new process. This newly created process is known as child process. The current process which is creating another child process is called the parent process. A child process uses the same program counter, CPU register, same files that are used by the parent process. Syntax #include #include pid_t fork(void); Return Value The fork() does not take any parameter, it returns integer values. It may return three types ...
Read MoreAssertions in C/C++
An assertion in C is a debugging tool that checks if a condition is true during program execution. When an assertion fails, the program displays an error message and terminates immediately. This helps catch programming errors early in the development process. In C programming, assertions are implemented using the assert() macro defined in the header file. The macro evaluates an expression and aborts the program if the expression is false. Syntax #include assert(expression); Parameters: expression − A condition that should be true. If it evaluates to false (0), the program terminates ...
Read MorePrint \"Hello World\" in C/C++ without using header files
In C/C++, we typically use header files to access standard library functions. The printf() function is declared in the "stdio.h" header file and is used to print data to the console. However, it's possible to print "Hello World" without including any header files by declaring the function prototype ourselves. Syntax int printf(const char *format, ...); Method 1: Using printf() Declaration in C In C, we can declare the printf() function prototype directly in our program without including stdio.h. The compiler will link to the standard library automatically − int printf(const char *format, ...
Read MoreImplement your own itoa() in C
In C programming, the itoa() function converts an integer to a string representation. However, itoa() is not part of the C standard library. Here we'll implement our own version using both the sprintf() approach and a manual conversion method. Syntax char* itoa(int value, char* str, int base); Method 1: Using sprintf() The sprintf() function formats and stores data in a string buffer instead of printing to console − #include #include char* my_itoa_sprintf(int number, char* str) { sprintf(str, "%d", number); return str; ...
Read MoreHeap overflow and Stack overflow in C
In C programming, memory management involves two primary areas: the heap and the stack. Both can experience overflow conditions that lead to program crashes or undefined behavior. Understanding these overflows is crucial for writing robust C programs. Heap Overflow The heap is a region of memory used for dynamic allocation. Functions like malloc(), calloc(), and realloc() allocate memory from the heap at runtime. Heap overflow occurs when the program exhausts available heap memory. This typically happens in two scenarios − Allocating Excessive Memory Attempting to allocate extremely large amounts of memory can cause heap overflow ...
Read MoreHow do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?
In this article we will see how to add two numbers without using arithmetic operators like +, ++, -, or --. This technique uses bitwise operations to simulate binary addition. To solve this problem, we can use binary adder logic. In digital circuits, we design half adder and full adder circuits that can add one-bit binary numbers. By cascading multiple adders, we can create circuits to add bigger numbers. In binary addition, we perform XOR operation for the sum bits, and AND operation for the carry bits. These principles are implemented here to add two numbers using only ...
Read MoreHow does “void *” differ in C and C++?
Both C and C++ support void pointers, but their behavior differs significantly. In C, a void pointer can be directly assigned to any other pointer type without explicit typecasting. However, in C++, assigning a void pointer to any other pointer type requires an explicit typecast. Syntax void *pointer_name; Void Pointer in C A void pointer (also called a generic pointer) in C is a special type of pointer that can point to any data type, but doesn't have any type by itself. It can hold the address of any variable (int, float, char, etc.). ...
Read MoreCan we use function on left side of an expression in C and C++?
In C and C++, you normally cannot use a function call on the left side of an assignment if it returns a value by copy, because function calls return non-assignable temporary values. However, there are specific cases where this is possible − Syntax // Invalid - function returns value by copy function_name() = value; // Compiler error // Valid - function returns pointer (C) *function_name() = value; // Dereference pointer // Valid - function returns reference (C++ only) function_name() = value; ...
Read More