Found 33676 Articles for Programming

Rename function in C/C++

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

399 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

Command Line and Variable Arguments in Python?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

632 Views

Command Line ArgumentsCommand line arguments are input parameters which allow user to enable programs to act in a certain way like- to output additional information, or to read data from a specified source or to interpret the data in a desired format.Python Command Line ArgumentsPython provides many options to read command line arguments. The most common ways are -Python sys.argvPython getopt modulePython argparse modulePython sys moduleThe sys module stores the command line arguments (CLA) into a list and to retrieve it, we use sys.argv. It’s a simple way to read command line arguments as string.import sys print(type(sys.argv)) print('The command ... Read More

How to write an empty function in Python?

AmitDiwan
Updated on 11-Aug-2022 12:05:44

2K+ Views

In this article, we will see how we can create an empty functions in Python. A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ). Here, we will see examples of Empty Functions. Empty Function Use the pass statement to write an empty function in Python −Example # Empty function in Python def demo(): pass Above, ... 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

Reloading modules in Python?

AmitDiwan
Updated on 16-Aug-2022 12:12:47

19K+ Views

The reload() is used to reload a previously imported module or loaded module. This comes handy in a situation where you repeatedly run a test script during an interactive session, it always uses the first version of the modules we are developing, even we have made changes to the code. In that scenario we need to make sure that modules are reloaded. The argument passed to the reload() must be a module object which is successfully imported before. Few points to understand, when reload() is executed − Python module’s code is recompiled and the module-level code re-executed, defining a ... 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

735 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

Inplace vs Standard Operators in Python

Chandu yadav
Updated on 30-Jul-2019 22:30:25

469 Views

Inplace Operator in PythonInplace operation is an operation which directly changes the content of a given linear algebra or vector or metrices without making a copy. Now the operators, which helps to do this kind of operation is called in-place operator.Let’s understand it with an a simple example -a=9 a += 2 print(a)output11Above the += tie input operator. Here first, a add 2 with that a value is updated the previous value.Above principle applies to other operators also. Common in place operators are -+=-=*=/=%=Above principle applies to other types apart from numbers, for example -language = "Python" language +="3" print(language)OutputPython3Above ... Read More

How are variables scoped in C

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

100 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

Advertisements