Found 1401 Articles for C

Const Qualifier in C

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

2K+ Views

We use the const qualifier to declare a variable as constant. That means that we cannot change the value once the variable has been initialized. Using const has a very big benefit. For example, if you have a constant value of the value of PI, you wouldn't like any part of the program to modify that value. So you should declare that as a const.Objects declared with const-qualified types may be placed in read-only memory by the compiler, and if the address of a const object is never taken in a program, it may not be stored at all. For ... Read More

Need of long data type in C

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

314 Views

In C or C++, there are four different datatypes, that are used for integer type data. These four datatypes are short, int, long and long long. Each of these datatypes takes different memory spaces. The size varies in different architecture and different operating systems. Sometimes int takes 4-bytes or sometimes it takes 2-bytes. This also happen for the compilers. So we can use cross compilers.The cross compilers are basically a compiler, which is capable of compiling for a platform other than current platform.So if we want to compile the following code in 32bit system, and 64-bit system, it will generate ... Read More

Benefits of C over other languages

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

2K+ Views

The C programming language was developed by Dennis Ritchie during early 1970. It was developed to redesign UNIX operating system.Earlier the B language, which was used for UNIX system, it has different drawbacks. It does not support structures, and did not understand datatypes. For this reason, the C language was introduced. C has high level functionality, and detailed feature for OS programming. The UNIX kernel was developed by using C.Advantages of C languageC is medium level language. It has both, the lower level and higher level functionality. We can use C to make driver or kernel level programs as well ... Read More

C/C++ Struct vs Class

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

287 Views

In C++ the structure and class are basically same. But there are some minor differences. These differences are like below.The class members are private by default, but members of structures are public. Let us see these two codes to see the differences.Example#include using namespace std; class my_class {    int x = 10; }; int main() {    my_class my_ob;    cout

What does the operation c=a+++b mean in C/C++?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

Let us consider in C or C++, there is a statement like:c = a+++b;Then what is the meaning of this line?Well, Let the a and b are holding 2 and 5 respectively. this expression can be taken as two different types.c = (a++) + bc = a + (++b)There are post increment operator, as well as pre increment operator. It depends on how they are used.There are two basic concepts. The precedence and the associativity. Now if we check the expression from left to right, so the result will be these two.c = (a++) + b → 2 + 5 ... Read More

Command line arguments example in C

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

415 Views

It is possible to pass some values from the command line to your C programs when they are executed. These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard-coding those values inside the code.The command line arguments are handled using main() function arguments where argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program. Following is a simple example which checks if there is any argument supplied from ... Read More

_Noreturn function specifier in C

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

134 Views

The _Noreturn function specifier is used to tell to the compiler that the function will not return anything. If the program uses some return statement inside it, the compiler will generate compile time error.Example Code#include main() {    printf("The returned value: %d", function); } char function() {    return 'T'; //return T as character }OutputThe program terminates abnormally [Warning] function declared 'noreturn' has a 'return' statementNow if it is a normal function it will work fine.Example Code#include int function() {    return 86; //try to return a value } main() {    printf("The returned value: %d", function()); }OutputThe returned value: 86

What happens when a function is called before its declaration in C?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

243 Views

If we do not use some function prototypes, and the function body is declared in some section which is present after the calling statement of that function. In such a case, the compiler thinks that the default return type is an integer. But if the function returns some other type of value, it returns an error. If the return type is also an integer, then it will work fine, sometimes this may generate some warnings.Example Code#include main() {    printf("The returned value: %d", function); } char function() {    return 'T'; //return T as character }Output[Error] conflicting types for 'function' ... Read More

What is the purpose of a function prototype in C/C++?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

6K+ Views

Here we will see what are the purpose of using function prototypes in C or C++. The function prototypes are used to tell the compiler about the number of arguments and about the required datatypes of a function parameter, it also tells about the return type of the function. By this information, the compiler cross-checks the function signatures before calling it. If the function prototypes are not mentioned, then the program may be compiled with some warnings, and sometimes generate some strange output.If some function is called somewhere, but its body is not defined yet, that is defined after the ... Read More

How can we return multiple values from a function in C/C++?

Vrundesha Joshi
Updated on 04-Oct-2023 21:21:06

25K+ Views

In C or C++, we cannot return multiple values from a function directly. In this section, we will see how to use some trick to return more than one value from a function. We can return more than one values from a function by using the method called “call by address”, or call by reference. In the invoker function, we will use two variables to store the results, and the function will take pointer type data. So we have to pass the address of the data. In this example, we will see how to define a function that can return ... Read More

Advertisements