Tapas Kumar Ghosh

Tapas Kumar Ghosh

185 Articles Published

Articles by Tapas Kumar Ghosh

Page 3 of 19

What is the correct way to use printf to print a size_t in C/C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 26K+ Views

In C programming, size_t is an unsigned integer type used to represent the size of objects and is commonly returned by functions like sizeof and strlen. To correctly print size_t variables, we should use the %zu format specifier instead of %d or other format specifiers. Syntax printf("%zu", size_t_variable); The %zu format specifier consists of − z − length modifier that specifies the argument corresponds to a size_t type u − conversion specifier for unsigned decimal integer Example 1: Basic size_t Printing This ...

Read More

Pre-increment and Post-increment concept in C/C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 12K+ Views

Both pre-increment and post-increment are used to increase a variable's value by 1, but they behave differently in expressions. Pre-increment (++i) increases the value before it is used, while post-increment (i++) increases it after the current expression is evaluated. Syntax // Pre-increment ++variable_name; // Post-increment variable_name++; Key Differences: Pre-increment (++i) − Increments the value first, then uses the new value in the expression Post-increment (i++) − Uses the current value in the expression, then increments it Pre-Increment Operator (++x) The pre-increment operator increments the variable's value by ...

Read More

exit(), abort() and assert() in C/C++

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 2K+ Views

In C programming, the exit(), abort(), and assert() functions are used for program termination and debugging. Each function serves a different purpose and is defined in different header files. The exit() Function The exit() function is used to terminate a program immediately in a normal way. It is defined in the header file and allows the program to return a status code to the operating system. Syntax void exit(int status_value); Parameters: status_value − The termination status code (0 indicates success, non-zero indicates error) Example In this example, the ...

Read More

Swap two variables in one line in C/C+

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 2K+ Views

In C programming, swapping two variables means exchanging the values stored in them. There are multiple ways to implement swapping using a single line statement. This article demonstrates various approaches to swap variable values efficiently. Syntax // General concept variable1 = new_value_of_variable2; variable2 = new_value_of_variable1; Example Scenario Let's consider the following input and expected output − Input: int a = 5; int b = 10; Output: a = 10 b = 5 Method 1: Using Arithmetic Operations This method uses arithmetic operations to swap variables without temporary storage. ...

Read More

What are Wild Pointers in C/C++?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 4K+ Views

In C, a wild pointer is a pointer that has not been initialized to a valid memory address. When a pointer is declared but not assigned a value, it contains garbage data and points to an unknown memory location, making it unpredictable and dangerous to use. Syntax data_type *pointer_name; // Uninitialized pointer (wild pointer) Example: Wild Pointer Behavior Here's an example demonstrating a wild pointer that attempts to access uninitialized memory − #include int main() { int *ptr; // Wild pointer - ...

Read More

How will you print numbers from 1 to 100 without using loop in C?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 4K+ Views

You can print numbers from 1 to 100 without using traditional loops by employing alternative control structures like recursive functions and goto statements. These methods achieve the same repetitive behavior through different mechanisms. Method 1: Using Recursion Recursion allows a function to call itself repeatedly until a base condition is met. We can use this property to print numbers sequentially without explicit loops − #include void printNumbers(int n) { if (n > 100) return; printf("%d ", n); ...

Read More

What is the size of void pointer in C/C++ ?

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 15-Mar-2026 9K+ Views

The size of void pointer varies from system to system. If the system is 16-bit, size of void pointer is 2 bytes. If the system is 32-bit, size of void pointer is 4 bytes. If the system is 64-bit, size of void pointer is 8 bytes. This is because a pointer stores memory addresses, and the size depends on the system's addressing capability. Syntax To find the size of a void pointer, use the sizeof() operator: sizeof(void*) sizeof(pointer_variable) Example: Finding Size of Void Pointer The following example demonstrates how to find the size ...

Read More

Errors in C/C++

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 28-Jul-2025 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

All pair combinations of 2 tuples in Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 11-Jul-2025 408 Views

Python tuples are immutable sequences that used to store collections of items. When working with two tuples, you may sometimes need to generate all possible pairs, where each pair contains one element from the first tuple and one from the second. In this article, we will learn different ways to generate all pair combinations from two tuples Following are input-output scenarios for pairing combinations of two tuples: Input: first_tuple = (1, 3) second_tuple = (7, 9) Output: [(1, 7), (1, 9), (3, 7), (3, 9), (7, 1), (7, 3), (9, 1), (9, 3)] Explanation: At index 0 of first_tuple pairs ...

Read More

Aligning table to X-axis using matplotlib Python

Tapas Kumar Ghosh
Tapas Kumar Ghosh
Updated on 11-Jul-2025 2K+ Views

The Python Matplotlib library allows us to create visual plots from given data. To make the data easier to read and relate to the chart, we can display it in the form of a table and position it directly below the corresponding bar chart. Since the x-axis runs horizontally, we arrange the table in the same direction so that each value aligns correctly under its corresponding bar. Based on this concept, we demonstrate the diagram as follows: Steps to Align a Table to the X-axis Using Matplotlib Following are the steps to create a table and store data ...

Read More
Showing 21–30 of 185 articles
« Prev 1 2 3 4 5 19 Next »
Advertisements