Found 1401 Articles for C

kbhit in C language

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

2K+ Views

Here we will see the kbhit functionality in C. The kbhit is basically the Keyboard Hit. This function is present at conio.h header file. So for using this, we have to include this header file into our code.The functionality of kbhit() is that, when a key is pressed it returns nonzero value, otherwise returns zero.Example#include #include main() {    char ch;    printf("Enter keys (ESC to exit)");    while (1) { //define infinite loop for taking keys       if (kbhit) {          ch = getch(); // Get typed character into ch     ... Read More

C function argument and return values

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

8K+ Views

Here we will see what are the different types of C functions based on the return values and arguments.So a function either can take some arguments, or nothing is taken. Similarly, a function can return something, otherwise does not return anything. So we can categorize them into four types.Function with No argument and No return type.Function with No argument and Return something.A function that takes argument but returns nothing.Functions that take an argument and also return something.Example#include void my_function() {    printf("This is a function that takes no argument, and returns nothing."); } main() {    my_function(); }OutputThis is ... Read More

abs(), labs(), llabs() functions in C/C++

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

118 Views

In the cstdlib library of C++, there are different functions for getting the absolute value except from abs. The abs are used basically for int type input in C, and int, long, long long in C++. The others are used for long, and long long type data etc. Let us see the usage of these functions.The abs() FunctionThis function is used for int type data. So this returns the absolute value of the given argument. The syntax is like below.int abs(int argument)Example#include #include #include using namespace std; main() {    int x = -145;    int y = 145;    cout

wcstoll() function in C/C++

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

94 Views

The wcstoll() function is used to convert the wide character string to long long integers. It sets the pointer to point to the first character after the last one. The syntax is like below.long long wcstoll(const wchar_t* str, wchar_t** str_end, int base)This function takes three arguments. These arguments are like below −str: This is the starting of a wide string.str_end: The str_end is set by the function to the next character, after the last valid character, if there is any character, otherwise null.base: This specifies the base. The base values can be of (0, 2, 3, …, 35, 36)This function ... Read More

ldexp() function in C/C++

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

123 Views

Here we will see what is the use of ldexp() method in C or C++. This function returns any variable x raise to the power of exp value. This takes two arguments x and exp.The syntax is like below.float ldexp (float x, int exp) double ldexp (double x, int exp) long double ldexp (long double x, int exp) double ldexp (T x, int exp)Now let us see one example to get a better idea.Example#include #include using namespace std; int main() {    double a = 10, res;    int exp = 2;    res = ldexp(a, exp); // Finds a*(2^exp)    cout

C qsort() vs C++ sort()

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

410 Views

Here we will see what are the differences between qsort() in C, and sort() in C++.The C provides qsort() function, that can be used for sorting an array. The function arguments and syntax is like below.void qsort(void *base, size_t num, size_t size, int (*comparator) (const void*, const void*));This function takes the base address of that array, the number of elements of that array. Size of each item in the array, and a comparator function.The C++ provides sort() function. This is present inside C++ STL. The arguments and syntax is like below.void sort(T first, T last, Compare c);Here the order of ... Read More

Difference between %p and %x in C/C++

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

9K+ Views

Here we will see what are the differences between %p and %x in C or C++. The %p is used to print the pointer value, and %x is used to print hexadecimal values. Though pointers can also be displayed using %u, or %x. If we want to print some value using %p and %x then we will not feel any major differences. The only difference that can be noticed is that the %p will print some leading zeros, but %x doesn’t.Example#include main() {    int x = 59;    printf("Value using %%p: %p", x);    printf("Value using %%x: %x", x); ... Read More

What is the use of `%p` in printf in C?

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

10K+ Views

In C we have seen different format specifiers. Here we will see another format specifier called %p. This is used to print the pointer type data. Let us see the example to get a better idea.Example#include main() {    int x = 50;    int *ptr = &x;    printf("The address is: %p, the value is %d", ptr, *ptr); }OutputThe address is: 000000000022FE44, the value is 50

Convert an int to ASCII character in C/C++

Nishtha Thakur
Updated on 05-Oct-2023 00:50:13

29K+ Views

In C or C++ the character values are stored as ASCII values. To convert int to ASCII we can add the ASCII of character ‘0’ with the integer. Let us see an example to convert int to ASCII values. Example #include int intToAscii(int number) {    return '0' + number; } main() {    printf("The ASCII of 5 is %d", intToAscii(5));    printf("The ASCII of 8 is %d", intToAscii(8)); } Output The ASCII of 5 is 53 The ASCII of 8 is 56

How to find the size of an int[] in C/C++?

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

7K+ Views

In this section, we will see how we can get the size of an integer array in C or C++? The size of int[] is basically counting the number of elements inside that array. To get this we can use the sizeof() operator. If the array name is passed inside the sizeof(), then it will return total size of memory blocks that are occupied by the array. Now if we divide it by the size of each element, then we can get number of elements.Let us see the following example to get the better idea about it.Example#include using namespace ... Read More

Advertisements