Found 33676 Articles for Programming

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

390 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

C++ Array of Strings

Farhan Muhamed
Updated on 21-Jul-2025 19:04:39

20K+ Views

A string is a sequence of characters used to store information as text. In C++, strings are represented as array of characters using the std::string class. In this article, we will learn what is an array of strings in C++, how to declare and initialize it, and how to access its elements. C++ Array of Strings Array of strings refer to an array where each element is a string. Just like a normal array, we can define an array of strings by specifying the data type as std::string and the size of the array inside square brackets. To initialize ... Read More

Complex numbers in C++

George John
Updated on 30-Jul-2019 22:30:25

9K+ Views

In this section we will see how to create and use complex numbers in C++. We can create complex number class in C++, that can hold the real and imaginary part of the complex number as member elements. There will be some member functions that are used to handle this class.In this example we are creating one complex type class, a function to display the complex number into correct format. Two additional methods to add and subtract two complex numbers etc.Example Live Demo#include using namespace std; class complex {    int real, img;    public:       complex() {   ... Read More

Builtin functions of GCC compiler in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 14:33:31

744 Views

When you want to write a program in C++, your compiler (like GCC) converts your code into computer language. While doing this, GCC offers some special functions called built-in functions. The built-in functions are predefined functions by the compiler itself, but not provided by any standard library. The GCC compiler provides several built-in functions. Some of these functions are listed below: __builtin_popcount(x) __builtin_parity(x) __builtin_clz(x) __builtin_ctz(x) The __builtin_popcount(x) Function This builtin function is used to count the number of 1s in an integer ... Read More

Wide char and library functions in C++

Revathi Satya Kondra
Updated on 10-Jun-2025 13:24:03

4K+ Views

Wide Characters Wide characters are similar to character datatype. The main difference is that char takes 1-byte space, but wide character takes 2-bytes (sometimes 4-byte depending on compiler) of space in memory. For 2-byte space wide character can hold 64K (65536) different characters. So the wide char can hold UNICODE characters. The UNICODE values are international standard which allows for encoding for characters virtually for any character of any language. Example 1: Size of a single wide character This program demonstrates how to declare a single wide character using wchar_t to print its value and memory size. #include using namespace ... Read More

Conversion constructor in C++?

Revathi Satya Kondra
Updated on 30-May-2025 17:36:12

877 Views

In C++, a conversion constructor is a special type of constructor that takes only one argument. It enables automatic type conversion from the argument's type to the class type. When an object of the class to be created from a single value(int). then the compiler will call the conversion constructor to create the object from that value. This can be implicit conversion of a value into a class object. Creating Conversion Constructor Following is the syntax to the Conversion Constructor in C++: class ClassName { public: ClassName(Type arg); // Conversion constructor }; Here, ... Read More

Type difference of character literals in C and C++

Akansha Kumari
Updated on 10-Jun-2025 17:17:06

698 Views

Character literals are those values, which are assigned to the variable of character data type. It is written as a single character enclosed in single quotes (' ') like 'A', 'b' or '2'. But if we see how these character literals are stored in memory, their type differs. In C the character literals are stored as type int, whereas the same character literal is stored as type char in C++. In this article, we will study about the differences between these two in detail. Type of character literal in C The type of character literals in C language is an integer ... Read More

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

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

2K+ Views

Here we will see the precedence of postfix++ and prefix++ in C or C++. The precedence of prefix ++ or -- has higher priority than dereference operator ‘*’ and postfix ++ or -- has priority higher than both prefix ++ and dereference operator ‘*’.When ptr is a pointer, then *ptr++ indicates *(ptr++) and ++*prt refers ++(*ptr)Example Live Demo#include using namespace std; int main() {    char arr[] = "Hello World";    char *ptr = arr;    ++*ptr;    cout

C++ Scope of Variables

George John
Updated on 30-Jul-2019 22:30:25

348 Views

A scope is a region of the program and broadly speaking there are three places, where variables can be declared −Inside a function or a block which is called local variables, In the definition of function parameters which is called formal parameters.Outside of all functions which is called global variables.We will learn what is a function and it's parameter in subsequent chapters. Here let us explain what are local and global variables.Local VariablesVariables that are declared inside a function or block are local variables. They can be used only by statements that are inside that function or block of code. ... Read More

Advertisements