
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

8K+ Views
In C and C++, arrays can store multiple values of the same data type. This problem is about finding how many elements are present in a statically declared int[] array (not pointers or dynamically allocated arrays). We'll learn how to find the size of an int[] in both C and C++. Let's understand this with an example: //Example 1 input: int numbers[] = {10, 20, 30, 40, 50}; This array has 5 elements. Output: Number of elements: 5 //Example 2: Input: int values[] = {1, 2, 3}; This array has 3 elements. Output: Number of elements: 3 ... Read More

525 Views
Here we will see how the copy constructors are implemented in C++. Before discussing that we should know what is the copy constructor.The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to −Initialize one object from another of the same type.Copy an object to pass it as an argument to a function.Copy an object to return it from a function.If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer ... Read More

295 Views
The C library function int remove(const char *filename) deletes the given filename so that it is no longer accessible.Following is the declaration for remove() function.int remove(const char *filename)This function takes the filename. This is the C string containing the name of the file to be deleted. On success, zero is returned. On error, -1 is returned, and errno is set appropriately.Example#include #include int main () { int ret; FILE *fp; char filename[] = "file.txt"; fp = fopen(filename, "w"); fprintf(fp, "%s", "This is tutorialspoint.com"); fclose(fp); ret = remove(filename); if(ret == 0) { ... Read More

400 Views
The C library function int rename(const char *old_filename, const char *new_filename) causes the filename referred to by old_filename to be changed to new_filenameFollowing is the declaration for rename() function.int rename(const char *old_filename, const char *new_filename)The parameters are old_filename − This is the C string containing the name of the file to be renamed and/or moved, new_filename − This is the C string containing the new name for the file.On success, zero is returned. On error, -1 is returned, and errno is set appropriately.Example#include int main () { int ret; char oldname[] = "file.txt"; char newname[] = ... Read More

2K+ Views
Here we will see what type of operations can be performed on struct variables. Here basically one operation can be performed for struct. The operation is assignment operation. Some other operations like equality check or other are not available for stack.Example#include typedef struct { //define a structure for complex objects int real, imag; }complex; void displayComplex(complex c){ printf("(%d + %di)", c.real, c.imag); } main() { complex c1 = {5, 2}; complex c2 = {8, 6}; printf("Complex numbers are:"); displayComplex(c1); displayComplex(c2); }OutputComplex numbers are: (5 + 2i) (8 + 6i)This works fine as ... Read More

340 Views
Here we will see how the preprocessors are working in C or C++. Let us see what are the preprocessors.The preprocessors are the directives, which give instructions to the compiler to preprocess the information before actual compilation starts.All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not C++ statements, so they do not end in a semicolon (;).You already have seen a #include directive in all the examples. This macro is used to include a header file into the source file.There are number of preprocessor directives supported ... Read More

4K+ Views
Here we will see what is the meaning of volatile qualifier in C++. The volatile qualifier is applied to a variable when we declare it. It is used to tell the compiler, that the value may change at any time. These are some properties of volatile.The volatile keyword cannot remove the memory assignmentIt cannot cache the variables in register.The value cannot change in order of assignment.Let us see, how we can use the volatile keyword.volatile int a; int volatile a;Here these two declarations are correct. Like other datatypes, we can use volatile pointers, structures, unions etc. The volatile structures and ... Read More

736 Views
Here we will see what is re-declaration of global variables in C. Does C supports this or not. Let us see the following code to get the idea about it.Example#include int main(){ int a; int a = 50; printf("a is : %d", a); }Output[Error] redeclaration of 'a' with no linkageSo we can see that we cannot re-declare local variables. Now let us see what will be the output for global variables.Example#include int a; int a = 50; int main(){ printf("a is : %d", a); }Outputa is : 50So global variables are not creating any ... Read More

101 Views
Here we will see how the C variables are scoped. The variables are always statically scoped in C. Binding of a variable, can be determined by the program text. These are independent of runtime function call stack.Let us see one example to get the idea.Example# include int x = 0; int my_function() { return x; } int my_function2() { int x = 1; return my_function(); } int main(){ printf("The value is: %d", my_function2()); }OutputThe value is: 0Here the result is 0. Because the value returned by my_function() is not depends on the function, which is ... Read More

67K+ Views
In C++, cin.ignore() is a built-in function that belongs to the istream class and is defined in the header. It is used to skip characters left in the input buffer, especially the newline character (''), which can cause issues with input operations like getline(). In this article, we will explain the use of cin.ignore() in C++. Syntax of cin.ignore() Below is the syntax of the cin.ignore() function. cin.ignore(numeric_value, delimiter_char); // Example: cin.ignore(1000, ''); Here, numeric_value is the maximum number of characters to skip, and delimiter_char is the character at which the input should stop ... Read More