Found 1401 Articles for C

pow() function in C

karthikeya Boyini
Updated on 26-Jun-2020 08:33:04

7K+ Views

The function pow() is used to calculate the power raised to the base value. It takes two arguments. It returns the power raised to the base value. It is declared in “math.h” header file.Here is the syntax of pow() in C language, double pow(double val1, double val2);Here, val1 − The base value whose power is to be calculated.val2 − The power value.Here is an example of pow() in C language, Example#include #include int main() {    double x = 5.5;    double y = 4.0;    double p;    p = pow(x, y);    printf("The value : %lf", p);   ... Read More

Static functions in C

Samual Sam
Updated on 26-Jun-2020 08:34:44

20K+ Views

A static function in C is a function that has a scope that is limited to its object file. This means that the static function is only visible in its object file. A function can be declared as static function by placing the static keyword before the function name.An example that demonstrates this is given as follows −There are two files first_file.c and second_file.c. The contents of these files are given as follows −Contents of first_file.cstatic void staticFunc(void) {    printf("Inside the static function staticFunc() "); }Contents of second_file.cint main() {    staticFunc();    return 0; }Now, if the above ... Read More

exit(), abort() and assert() in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:35:45

2K+ Views

exit()The function exit() is used to terminate the calling function immediately without executing further processes. As exit() function calls, it terminates processes. It is declared in “stdlib.h” header file. It does not return anything.Here is the syntax of exit() in C language, void exit(int status_value);Here, status_value − The value which is returned to parent process.Here is an example of exit() in C language, Example Live Demo#include #include int main() {    int x = 10;    printf("The value of x : %d", x);    exit(0);    printf("Calling of exit()");    return 0; }OutputThe value of x : 10In the ... Read More

strftime() function in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:36:22

589 Views

The function strftime() is used to format the time and date as a string. It is declared in “time.h” header file in C language. It returns the total number of characters copied to the string, if string fits in less than size characters otherwise, returns zero.Here is the syntax of strftime() in C language, size_t strftime(char *string, size_t size, const char *format, const struct tm *time_pointer)Here, string − Pointer to the destination array.size − Maximum number of characters to be copied.format − Some special format specifiers to represent the time in tm.time_pointer − Pointer to tm structure that contains the ... Read More

Print “Hello World” in C/C++ without using header files

Samual Sam
Updated on 26-Jun-2020 08:36:48

611 Views

Generally, we use header files in C/C++ languages to access the built-in functions like int, char, string functions. The function printf() is also a built-in function which is declared in “stdio.h” header file and it is used to print any kind of data on console.Here is an example to print without header files in C language, Exampleint printf(const char *text, ...); int main() {    printf( "Hello World" );    return 0; }OutputHello WorldIn the above program, we printed “Hello World” without using any header file in the program by declaring the printf() function. The declaration of printf() is as ... Read More

Swap two variables in one line in C/C+

karthikeya Boyini
Updated on 26-Jun-2020 08:37:21

1K+ Views

Here is an example of swapping in C language, Example Live Demo#include int main() {    int a = 28, b = 8;    a += b -= a = b - a; // method 1    printf("After Swapping : %d\t%d", a, b);    (a ^= b), (b ^= a), (a ^= b); // method 2    printf("After Swapping again : %d\t%d", a, b);    return 0; }OutputAfter Swapping : 828 After Swapping again : 288In the above program, there are two variables a and b and initialized with the values 28 and 8 respectively. There are so many methods ... Read More

What are Wild Pointers in C/C++?

karthikeya Boyini
Updated on 26-Jun-2020 08:12:20

3K+ Views

Pointers store the memory addresses. Wild pointers are different from pointers i.e. they also store the memory addresses but point the unallocated memory or data value which has been deallocated. Such pointers are known as wild pointers.A pointer behaves like a wild pointer when it is declared but not initialized. That is why, they point any random memory location.Here is an example of wild pointers in C++ language,Example Live Demo#include using namespace std; int main() {    int *arr;    for(int i=0; i

How will you print numbers from 1 to 100 without using loop in C?

karthikeya Boyini
Updated on 26-Jun-2020 08:15:23

3K+ Views

There are several methods to print numbers without using loops like by using recursive function, goto statement and creating a function outside main() function.Here is an example to print numbers in C language,Example Live Demo#include int number(int val) {    if(val

(limits.h) in C/C++

Samual Sam
Updated on 26-Jun-2020 08:16:40

946 Views

The header files “limits.h” exists in C language while in C++ language. Several macros are defined in these header files. The limits specify that variable cannot store values beyond the limits.Some macros in “limits.h” or header file are as followsCHAR_BITLONG_MINLONG_MAXCHAR_MINCHAR_MAXINT_MININT_MAXSHRT_MINSHRT_MAXULONG_MAXHere is an example of in C++ language,Example Live Demo#include #include #include using namespace std; int main() {    int x = 28;    int a = CHAR_BIT*sizeof(x);    stack s;    cout

isgraph() C library function

karthikeya Boyini
Updated on 26-Jun-2020 08:17:52

93 Views

The function isgraph() is used to check that the passed character has a graphical representation or not. It is declared in “ctype.h” header file.Here is the syntax of isgraph() in C language, int isgraph(int char);Here is an example of isgraph() in C language, Example Live Demo#include #include int main() {    int a = '';    int b = '8';    int c = 's';    if(isgraph(a))    printf("The character has graphical representation");    else    printf("The character isn’t having graphical representation");    if(isgraph(b))    printf("The character has graphical representation");    else    printf("The character isn’t having graphical representation");    if(isgraph(c)) ... Read More

Advertisements