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 10 of 597
Name Mangling and extern "C" in C++
In C++, function overloading allows multiple functions with the same name but different parameter types or numbers. However, this creates a problem: how does the compiler distinguish between these functions in the object code? The solution is a technique called name mangling. Syntax extern "C" { // C function declarations } What is Name Mangling? Name mangling is a technique where the compiler modifies function names by adding information about parameters to create unique identifiers. C++ has no standardized name mangling scheme, so different compilers use different approaches. Example: ...
Read MoreWhat does it mean when a numeric constant in C/C++ is prefixed with a 0?
When a numeric constant in C is prefixed with a 0, it indicates that the number is an octal number (base 8). Octal literals must start with 0 to distinguish them from decimal numbers. For example, the octal number 25 is written as 025 in C. Syntax 0octal_digits Where octal_digits are valid octal digits (0-7). Example: Octal Number Conversion The following program demonstrates how octal literals are converted to decimal values − #include int main() { int a = 025; /* Octal ...
Read MoreIncompatibilities between C and C++
Here we will see some incompatibilities between C and C++. Some C codes that can be compiled using C compiler, but does not compile in C++ compiler and returns errors. Syntax // C allows various syntaxes that C++ rejects // Old-style function declarations, implicit int, multiple declarations, etc. Example 1: Old-Style Function Declarations C allows defining functions with parameter types specified after the parameter list − #include void my_function(x, y) int x; int y; { printf("x = %d, y = %d", x, y); } ...
Read Morenextafter() and nexttoward() in C/C++
The nextafter() and nexttoward() functions in C are used to find the next representable floating-point value after a given number in a specified direction. These functions are part of the math.h library and are useful for precise floating-point arithmetic operations. Syntax double nextafter(double x, double y); float nextafterf(float x, float y); long double nextafterl(long double x, long double y); double nexttoward(double x, long double y); float nexttowardf(float x, long double y); long double nexttowardl(long double x, long double y); Parameters x − The starting value y − The direction value. The function ...
Read MoreDifference between "int main()" and "int main(void)" in C/C++?
In C programming, you might notice two different ways to declare the main function: int main() and int main(void). While both are valid, there is a subtle but important difference in how C treats them. Syntax int main() int main(void) Key Difference In C, int main() means the function can accept any number of arguments, while int main(void) explicitly specifies that the function takes no arguments. In C++, both forms are equivalent and mean "no arguments". Example 1: Function Without void When a function is declared without void, C allows it to ...
Read MoreWhat 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 More