C Articles - Page 117 of 134

Execute both if and else statements simultaneously in C/C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

231 Views

In this section we will see how to execute the if and else section simultaneously in a C or C++ code. This solution is little bit tricky.When the if and else are executed one after another then it is like executing statements where if-else are not present. But here we will see if they are present how to execute them one after another.Example Code#include using namespace std; int main() {    int x = 10;    if(x > 5)   {       lebel_1: cout

Implement your own itoa() in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

2K+ Views

In this section we will see how to convert an integer number to a string.The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.Input: User will put some numeric value say 42Output: This program will return the string equivalent result of that number like “42”Algorithm:Step 1: Take a number as argument Step 2: Create an empty ... Read More

Switch case statement in C

Nitya Raut
Updated on 30-Jul-2019 22:30:25

1K+ Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.The syntax for a switch statement in C programming language is as follows −switch(expression) {    case constant-expression :       statement(s);       break; /* optional */    case constant-expression :       statement(s);       break; /* optional */       /* you can have any number of case statements */    default : /* Optional */       ... Read More

Heap overflow and Stack overflow in C

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

6K+ Views

Heap OverflowHeap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables.Heap overflow occurs when −A) If we allocate dynamic large number of variables −int main() {    float *ptr = (int *)malloc(sizeof(float)*1000000.0)); }B) If we continuously allocate memory and do not free after using it.int main() {    for (int i=0; i

How do I add two numbers without using ++ or + or any other arithmetic operator in C/C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

339 Views

In this article we will see how to add two numbers without using arithmetic operators like +, ++, -, or --.To solve this problem, we can solve them using binary adder logic. In that case we were designed half adder and full adder. These adders can add one bit binary numbers. By cascading multiple adders, we have can create circuit to add bigger numbers.In that adder, we have performed XOR operation among the numbers, then for the carry we were performing the ANDing logic. These features are implemented here to add two numbers.Example Code Live Demo#include using namespace std; int ... Read More

What does “dereferencing” a pointer mean in C/C++?

Samual Sam
Updated on 08-Nov-2024 16:56:54

22K+ Views

Dereferencing is used to access or manipulate data contained in memory location pointed to by a pointer. *(asterisk) is used with pointer variable when dereferencing the pointer variable, it refers to variable being pointed, so this is called dereferencing of pointers. int main() {  int a = 7, b ;  int *p; // Un-initialized Pointer  p = &a; // Stores address of a in ptr  b = *p; // Put Value at ptr in b }Here, address in p is basically address of a variable.Complete tutorial on dereferencing: C++ Dereferencing

How does “void *” differ in C and C++?

Revathi Satya Kondra
Updated on 10-Jun-2025 14:27:29

640 Views

Both languages (C and C++) support void pointers, but their behaviour is different. In C, a void pointer can be directly assigned to any other pointer type without the need for a typecast. However, in C++, assigning a void pointer to any other pointe type require an explicit typecast. In this article, we will learn the differences between void pointers in C and C++.. 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 ... Read More

Data type of character constants in C and C++

Revathi Satya Kondra
Updated on 30-May-2025 17:31:42

1K+ Views

The character constant is a constant that is enclosed in a single quote (' '). It represents the integer value (i.e., ASCII) of the character. In C programming language, the data type of character constant is an integer (represented by int) and it needs 4 bytes to store a character constant. For example: 'A', '1', '3', etc., are the character constants. In C++, the data type for character constants is char and it needs only 1 byte to store a character constant. Here are the size of different data types in bytes: ... Read More

Can we use function on left side of an expression in C and C++?

Revathi Satya Kondra
Updated on 17-Jun-2025 14:49:02

402 Views

In C, you cannot use a function call on the left side of an assignment if it returns a value because function calls return non-assignable values. For example, function_name() = value; However, if the function returns a pointer, you can dereference it to assign a value. For example, *function_name() = value; In C++, the same rule applies. You can use the returned reference/pointer on the left side to modify the original variable which is valid only if it returns a reference. function_name() = value; Note: References allow direct access to variables, and pointers allow indirect access via dereferencing. ... Read More

Printing Heart Pattern in C

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

9K+ Views

In this program we will see how to print heart shaped pattern in C. The heart shape pattern will be look like thisNow if we analyze this pattern, we can find different section in this pattern. The base of the heart is an inverted triangle; the upper portion has two different peaks. Between these two peaks there is a gap. To make this pattern we have to manage these parts into our code to print the pattern like this.Example Live Demo#include int main() {    int a, b, line = 12;    for (a = line/2; a

Advertisements