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 11 of 597
What is long long in C/C++?
In C programming, long long is an extended integer data type that provides a larger range for storing integer values than the standard long type. The long long type was introduced in C99 standard to handle very large integer values that exceed the capacity of regular int or long types. Syntax long long variable_name; long long int variable_name; // equivalent to above Size and Range The long long data type is guaranteed to be at least 64 bits (8 bytes) according to the C standard. The exact size may vary between systems, but it's ...
Read Moreabs(), labs(), llabs() functions in C/C++
The C standard library provides different functions to calculate the absolute value of integers based on their data types. The abs(), labs(), and llabs() functions handle int, long, and long long data types respectively, returning the non-negative value of their arguments. Syntax int abs(int n); long labs(long n); long long llabs(long long n); The abs() Function The abs() function returns the absolute value of an integer argument. It is defined in stdlib.h and works with int type data − Example #include #include int main() { ...
Read Moreldexp() function in C/C++
The ldexp() function in C computes the result of multiplying a floating-point number by an integral power of 2. It calculates x * 2^exp where x is a floating-point value and exp is an integer exponent. Syntax float ldexp(float x, int exp); double ldexp(double x, int exp); long double ldexp(long double x, int exp); Parameters x − The floating-point base value exp − The integer exponent representing power of 2 Return Value Returns x * 2^exp. If the result is too large to represent, it returns HUGE_VAL (infinity). Example ...
Read MoreC qsort() vs C++ sort()
The qsort() function in C and sort() function in C++ are both used for sorting arrays, but they differ significantly in implementation, performance, and usage. Understanding these differences helps choose the right sorting approach for your program. C qsort() Syntax void qsort(void *base, size_t num, size_t size, int (*comparator)(const void*, const void*)); This function takes the base address of the array, number of elements, size of each element, and a comparator function. C++ sort() Syntax void sort(T first, T last, Compare c); Here T represents iterators, and the order of ...
Read MoreConvert an int to ASCII character in C/C++
In C, every character like 'A', 'b', '3', or '@' is stored as a number called its ASCII value. For example, 'A' is 65, and 'a' is 97. Given an integer like 97, we can convert it to its corresponding ASCII character which is 'a'. Syntax char character = (char)asciiValue; We can convert an integer to an ASCII character using simple methods. Here are two common approaches − Typecasting to Convert int to ASCII Character Using printf for int to ASCII Conversion Method 1: Typecasting to Convert int to ASCII Character ...
Read MoreHow to find the size of an int[] in C/C++?
In C programming, finding the size of a statically declared int[] array means determining how many elements it contains. This is different from finding the memory size − we want the element count. The sizeof operator is the primary method for this in C. Syntax int array_length = sizeof(array) / sizeof(array[0]); Method 1: Using sizeof Operator The sizeof operator returns the total memory occupied by an array in bytes. Dividing this by the size of one element gives us the number of elements. This works only for statically declared arrays − #include ...
Read MoreAddress of a function in C or C++
In C programming, every function is stored in the computer's memory and has a unique memory address, just like variables. We can access and display these function addresses to understand how functions are stored in memory. Syntax functionName // Returns address of the function (void*)functionName // Cast to void pointer for printing Accessing Address of a Function To access the address of a function, we use its name without parentheses. When we write hello() with parentheses, we're calling the function. But when we write just hello, it ...
Read MoreConvert C/C++ program to Preprocessor code
Here we will see how to generate the preprocessed or preprocessor code from the source code of a C or C++ program. To see the preprocessed code using gcc compiler, we have to use the '-E' option with the gcc. The preprocessor includes all of the # directives in the code, and also expands the MACRO function. Syntax gcc -E program.c Example Let's create a simple C program with macro definitions and see how the preprocessor expands them − #include #define PI 3.1415 #define SQUARE(x) ((x) * (x)) int ...
Read MoreUninitialized primitive data types in C/C++
In C programming, uninitialized primitive data types contain unpredictable values called "garbage values". The C standard does not guarantee that these variables will be initialized to zero or any specific value. The actual values depend on what was previously stored in those memory locations. Syntax data_type variable_name; // Uninitialized variable data_type variable_name = initial_value; // Initialized variable Example: Uninitialized Variables Let's examine what happens when we declare variables without initializing them − #include int main() { char a; float b; ...
Read MoreConvert C/C++ code to assembly language
Assembly language is a low-level programming language that provides a human-readable representation of machine code. The GNU Compiler Collection (GCC) allows us to convert C/C++ source code into assembly language for analysis and optimization purposes. Syntax gcc -S source_file.c gcc -S source_file.cpp Note: To use gcc, you need to install it on your system. On Ubuntu/Debian: sudo apt install gcc, on Windows: install MinGW or use WSL. Parameters -S − Generate assembly code and stop before assembling source_file − The C/C++ source file to convert Example: Simple C ...
Read More