Found 34494 Articles for Programming

scanf() and fscanf() in C

karthikeya Boyini
Updated on 24-Jun-2020 11:17:07

2K+ Views

Function scanf()The function scanf() is used to read formatted input from stdin in C language. It returns the whole number of characters written in it otherwise, returns a negative value.Here is the syntax of scanf() in C language, int scanf(const char *characters_set)Here is an example of scanf() in C language, Example Live Demo#include int main () {    char s[20];    printf("Enter a string : ");    scanf("%s", s);    printf("Entered string : %s", s);    return(0); }OutputEnter a string : Peter! Entered string : Peter!Function fscanf()The function fscanf() is used to read the formatted input from the given stream ... Read More

Difference between %d and %i format specifier in C

Samual Sam
Updated on 24-Jun-2020 11:17:57

2K+ Views

Format Specifier %dThe format specifier %d takes integer value as a signed decimal integer value which means values should be decimal whether it is negative or positive.Here is an example of format specifier %d in C language, Example Live Demo#include int main() {    int v1 = 7456;    int v2 = -17346;    printf("The value in decimal form : %d", v1);    printf("The value in negative : %d", v2);    return 0; }OutputThe value in decimal form : 7456 The value in negative : -17346Format Specifier %iThe format specifier %i takes integer value as an integer value which means ... Read More

atol(), atoll() and atof() functions in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:18:30

553 Views

atol() FunctionThe function atol() converts string into a long integer. It returns zero, when no conversion is performed. It returns the converted long int value.Here is the syntax of atol in C++ language,long int atol(const char *string)Here is an example of atol() in C++ language,Example Live Demo#include using namespace std; int main() {    long int a;    char str[20] = "538756";    a = atol(str);    cout

Const member functions in C++

Samual Sam
Updated on 24-Jun-2020 11:19:02

17K+ Views

The const member functions are the functions which are declared as constant in the program. The object called by these functions cannot be modified. It is recommended to use const keyword so that accidental changes to object are avoided.A const member function can be called by any type of object. Non-const functions can be called by non-const objects only.Here is the syntax of const member function in C++ language, datatype function_name const();Here is an example of const member function in C++, Example Live Demo#include using namespace std; class Demo {    int val;    public:    Demo(int x = 0) { ... Read More

Ceil and floor functions in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:19:37

4K+ Views

The ceil FunctionThe ceil function returns the smallest possible integer value which is equal to the value or greater than that. This function is declared in “cmath” header file in C++ language. It takes single value whoes ceil value is to be calculated. The datatype of variable should be double/float/long double only.Here is the syntax of ceil function in C++ language, double ceil(double x); float ceil(float x);Here is an example of ceil function in C++ language, Example Live Demo#include #include using namespace std; int main() {    float var = 1234.25;    float res;    res = ceil(var);   ... Read More

new and delete operator in C++

Samual Sam
Updated on 24-Jun-2020 11:20:50

14K+ Views

The new operatorThe new operator requests for the memory allocation in heap. If the sufficient memory is available, it initializes the memory to the pointer variable and returns its address.Here is the syntax of new operator in C++ language, pointer_variable = new datatype;Here is the syntax to initialize the memory, pointer_variable = new datatype(value);Here is the syntax to allocate a block of memory, pointer_variable = new datatype[size];Here is an example of new operator in C++ language, Example#include using namespace std; int main () {    int *ptr1 = NULL;    ptr1 = new int;    float *ptr2 = new ... Read More

CHAR_BIT in C++

karthikeya Boyini
Updated on 24-Jun-2020 11:21:26

580 Views

The CHAR_BIT is the number of bits in char. It is declared in “limits.h” header file in C++ language. It is of 8-bits per byte.Here is an example of CHAR_BIT in C++ language,Example Live Demo#include using namespace std; int main() {    int x = 28;    int a = CHAR_BIT*sizeof(x);    stack s;    cout

swap() function in C++

Samual Sam
Updated on 24-Jun-2020 11:22:01

21K+ Views

The swap() function is used to swap two numbers. By using this function, you do not need any third variable to swap two numbers.Here is the syntax of swap() in C++ language, void swap(int variable_name1, int variable_name2);If we assign the values to variables or pass user-defined values, it will swap the values of variables but the value of variables will remain same at the actual place.Here is an example of swap() in C++ language, Example Live Demo#include using namespace std; int main() {    int x = 35, y = 75;    printf("Value of x :%d", x);    printf("Value of ... Read More

iswdigit() function in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:09:44

157 Views

The function iswdigit() is a built-in function in C/C++. It checks whether the wide character is a decimal digit or not. It is declared in “cwctype” header file in C++ language while “ctype.h” in C language. It takes a single character which is known as wide character.The characters from 0 to 9 are classified as decimal digits. If the wide character is not a digit, it will return zero(0). If character is digit, it will return non-zero value.Here is the syntax of iswdigit() in C++ language, int iswdigit(ch)Here is an example of iswdigit() in C++ language, Example Live Demo#include #include ... Read More

towupper() function in C/C++

Samual Sam
Updated on 24-Jun-2020 11:10:04

167 Views

The function iswupper() is a built-in function in C/C++. It converts the wide character into upper case. It is declared in “cwctype” header file in C++ language while “ctype.h” in C language. It takes a single character which is known as wide character. If the character is upper case, it is converted into it, otherwise no modifications happen.Here is the syntax of towupper() in C++ language, wint_t towupper( wint_t ch );Here is an example of towupper() in C++ language, Example#include #include #include using namespace std; int main() {    wchar_t s[] = L"hello world!";    wcout Read More

Advertisements