C++ Articles - Page 619 of 719

Remove function in C/C++

Smita Kapse
Updated on 30-Jul-2019 22:30:25

303 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

Rename function in C/C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

405 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

Operations on struct variables in C

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

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

How a Preprocessor works in C/C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

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

“volatile” qualifier in C

Anvi Jain
Updated on 30-Jul-2019 22:30:25

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

Redeclaration of global variable in C

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

757 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

How are variables scoped in C

Anvi Jain
Updated on 30-Jul-2019 22:30:25

107 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

What is the use of cin.ignore() in C++?

Nishu Kumari
Updated on 11-Jun-2025 15:09:43

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

How to write a singleton class in C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

1K+ Views

Singleton design pattern is a software design principle that is used to restrict the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. For example, if you are using a logger, that writes logs to a file, you can use a singleton class to create such a logger. You can create a singleton class using the following code.Example#include using namespace std; class Singleton {    static Singleton *instance;    int data;    // Private constructor so that no objects can be created.    Singleton() {   ... Read More

What is volatile keyword in C++?

Akansha Kumari
Updated on 15-Jul-2025 17:06:41

12K+ Views

C++ Volatile KeywordIn C++, the volatile keyword is a type qualifier that tells the compiler that the value of a variable may be changed at any time unexpectedly, so it should not optimize access to that variable. This change in a variable may be influenced by any external factors such as hardware, signal handlers, or concurrent threads. This concept of volatile is mostly used when working with systems programming, embedded systems, and multi-threaded applications. SyntaxHere, a variable is declared volatile, which means the compiler volatile data_type variable_name; Example This example represents a variable whose value may be changed from an external source. ... Read More

Advertisements