C++ Articles

Page 12 of 597

C/C++ Struct vs Class

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 501 Views

In C programming, there is no class keyword − only structures (struct) are available. However, understanding the conceptual differences between struct and class is important for C programmers who may work with C++. In C, structures are used to group related data together. Syntax struct structure_name { data_type member1; data_type member2; // ... more members }; Example: Basic Structure in C In C, all structure members are accessible by default − #include struct my_struct { ...

Read More

What does the operation c=a+++b mean in C/C++?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 2K+ Views

In C, the expression c = a+++b is parsed by the compiler using the "maximal munch" rule, which means it reads the longest possible token sequence. This expression is interpreted as c = (a++) + b, where a++ is the post-increment operator applied to variable a. Syntax c = a++ + b; // Post-increment a, then add b c = a + ++b; // Pre-increment b, then add to a The key difference lies in operator precedence and associativity. The post-increment operator (++) has higher precedence than the addition ...

Read More

Assertions in C/C++

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 667 Views

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 More

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

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 478 Views

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 More

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

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 15-Mar-2026 774 Views

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 More

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

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 15-Mar-2026 492 Views

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

Precedence of postfix ++ and prefix ++ in C/C++

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 2K+ Views

In C programming, understanding operator precedence between prefix increment (++var), postfix increment (var++), and dereference operator (*) is crucial for writing correct pointer code. The precedence order is: postfix operators have highest precedence, followed by prefix operators, then dereference. Syntax ++*ptr // Equivalent to ++(*ptr) - increment value at ptr *ptr++ // Equivalent to *(ptr++) - dereference then increment pointer (*ptr)++ // Increment value at ptr (postfix) Precedence Rules Postfix ++/-- has highest precedence Prefix ++/-- and dereference * have same precedence (right-to-left associativity) When ptr is a pointer: *ptr++ means ...

Read More

Type difference of character literals in C and C++

Akansha Kumari
Akansha Kumari
Updated on 15-Mar-2026 797 Views

Character literals are values assigned to character data type variables. They are written as single characters enclosed in single quotes (' ') like 'A', 'b' or '2'. However, the type of character literals differs between C and C++. In C, character literals are stored as type int, whereas in C++ they are stored as type char. This fundamental difference affects memory usage and type safety. Syntax 'character' // Character literal syntax Type of Character Literal in C In C, character literals have type int and occupy 4 bytes of memory. This happens ...

Read More

Line Splicing in C/C++

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 15-Mar-2026 816 Views

In C programming, line splicing is a preprocessor feature that allows you to split one long line of code into multiple lines by using a backslash (\) at the end of a line. The backslash tells the preprocessor to treat the next line as a continuation of the current line. Line splicing is processed before compilation during the preprocessing phase. It does not have parameters or return values − it simply affects how lines of code are interpreted by joining them together. Syntax line_of_code \ continuation_of_line The backslash must be the last character on ...

Read More

How can I get the list of files in a directory using C or C++?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 15-Mar-2026 17K+ Views

Listing files in a directory is used to write a program that opens a specified folder (e.g: "/myfiles"), reads its contents, and displays the names of each file and subfolder one by one. In C, to see all the files in a directory, you can use special system functions that let you read the directory's contents. In real life, we open folder to see the contents inside the files. Similarly, in C, we can write a program to display all the files and folders in a directory. Syntax DIR *opendir(const char *dirname); struct dirent *readdir(DIR ...

Read More
Showing 111–120 of 5,962 articles
« Prev 1 10 11 12 13 14 597 Next »
Advertisements