Ravi Ranjan has Published 59 Articles

How to “return an object” in C++?

Ravi Ranjan

Ravi Ranjan

Updated on 20-May-2025 19:38:05

5K+ Views

An object is an instance of a class. The memory is allocated only when an object is created and not when a class is defined. How to Return an Object in C++? An object can be returned by a function using the return keyword. There is no specific technique ... Read More

Difference Between Copy Constructor and Assignment Operator in C++

Ravi Ranjan

Ravi Ranjan

Updated on 20-May-2025 13:31:25

10K+ Views

A copy constructor is a type of constructor that uses another object from the same class that has been created previously, to initialize an object, whereas the assignment operator is used to assign a value to a variable. In this article, we will understand the difference between the copy constructor ... Read More

Why should I not #include 'bits/stdc++.h'?

Ravi Ranjan

Ravi Ranjan

Updated on 20-May-2025 13:30:05

166 Views

The is a header file that includes all the standard C++ library. It is used during coding contests, as it helps in saving time while solving the problem since programmers do not have to remember all the header files. In the software engineering approach, ... Read More

Why do we assume strncpy insecure in C/C++?

Ravi Ranjan

Ravi Ranjan

Updated on 16-May-2025 17:26:16

556 Views

The function strncpy() is used to copy the specified number of characters to the destination from the source. It is similar to the strcpy() function. In strncpy() function, we can specify the at most how many characters we want to copy from source to destination. In this article, we have ... Read More

When are static objects destroyed in C++?

Ravi Ranjan

Ravi Ranjan

Updated on 16-May-2025 17:25:38

3K+ Views

C++ Static Object A static object is declared with the static keyword. The static objects are initialized only once and stored in the static storage area. The static objects are only destroyed when the program terminates i.e. they live until program termination. In this article, we will understand static object, their ... Read More

How static variables in member functions work in C++?

Ravi Ranjan

Ravi Ranjan

Updated on 16-May-2025 17:24:40

1K+ Views

The static variables in C++ are defined using the static keyword. The static member variables in a class are shared by all the class objects as there is only one copy of them in memory, regardless of the number of objects of the class. All static data is initialized to ... Read More

How to print size of array parameter in a function in C++?

Ravi Ranjan

Ravi Ranjan

Updated on 15-May-2025 19:34:00

280 Views

To print the size of an array parameter in a function in C++, we will use the typeOf() operator. In this article, we have passed an array as an argument to the function. Our task is to print the size of this array in C++. Printing Size of Static ... Read More

What is the lifetime of a static variable in a C++ function?

Ravi Ranjan

Ravi Ranjan

Updated on 15-May-2025 19:33:43

17K+ Views

The lifetime of a static variable in a C++ function exists till the program executes. We can say the lifetime of a static variable is the lifetime of the program. The static variable is a variable that is declared using the static keyword. The space for the static variable is ... Read More

Accessing protected members in a C++ derived class

Ravi Ranjan

Ravi Ranjan

Updated on 15-May-2025 16:14:08

19K+ Views

A class in C++ has the following access modifiers: public, private, and protected, which contain the corresponding class members. The protected members in a class are similar to private members as they cannot be accessed from outside the class, but they can be accessed by derived classes or child classes, ... Read More

Why array index starts from zero in C/C++ ?

Ravi Ranjan

Ravi Ranjan

Updated on 15-May-2025 16:13:57

6K+ Views

An array arr[i] is interpreted as *(arr+i). Here, arr denotes the address of the first array element or the 0th index element. So *(arr+i) means the element is at i distance from the first element of the array. So, array index starts from 0 as initially i is 0 which ... Read More

Advertisements