Found 1452 Articles for C

strcspn() in C

karthikeya Boyini
Updated on 26-Jun-2020 07:52:51

203 Views

The function strcspn() counts the number of characters before first match of characters in both strings. This is declared in “string.h” header file. It returns the number of characters of first string before the occurrence of first matched character.Here is the syntax of strcspn() in C language, size_t strcspn(const char *string1, const char *string2)Here, string1 − The first string which is to be scanned.string2 − The second string which is used to search the matching character in first string.Here is an example of strcspn() in C language, Example Live Demo#include #include int main() {    char str1[] = "Helloworld!";    char ... Read More

iswpunct() function in C/C++

Samual Sam
Updated on 26-Jun-2020 07:53:21

115 Views

The function iswpunct() is used to check that the passing wide character is a punctuation or not. It returns zero, if it is not a punctuation, otherwise it returns a non-zero value. It is declared in “cwctype” header file.Here is the syntax of iswpunct()int iswpunct(wint_t character);Here is an example of iswpunct()Example#include #include using namespace std; int main() {    wint_t a = '!';    wint_t b = 'a';    if(iswpunct(a))    printf("The character is a punctuation.");    else    printf("The character is not a punctuation.");    if(iswpunct(b))    printf("The character is a punctuation.");    else    printf("The character is not ... Read More

iswblank() function in C/C++

Samual Sam
Updated on 26-Jun-2020 07:55:24

139 Views

The function iswblank() is used to check that the passed wide character is blank or not. It is basically a space character and it also considers tab character(\t). This function is declared in “ctype.h” header file in C language and “cctype”” header file in C++ language.Here is the syntax of isblank() in C++ language, int iswblank(wint_t char);Here is an example of iswblank() in C++ language, Example Live Demo#include #include using namespace std; int main() {    wchar_t s[] = L"The space between words.";    int i = 0;    int count = 0;    while(s[i]) {       ... Read More

isblank() in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 07:56:11

587 Views

The function isblank() is used to check that the passed character is blank or not. It is basically a space character and it also considers tab character(\t). This function is declared in “ctype.h” header file in C language and “cctype”” header file in C++ language.Here is the syntax of isblank() in C++ language, int isblank(int char);Here is an example of isblank() in C++ language, Example Live Demo#include #include using namespace std; int main() {    string s = "The space between words. ";    int i = 0;    int count = 0;    while(s[i]) {       ... Read More

What is the size of void pointer in C/C++?

karthikeya Boyini
Updated on 26-Jun-2020 07:42:28

6K+ Views

The size of void pointer varies system to system. If the system is 16-bit, size of void pointer is 2 bytes. If the system is 32-bit, size of void pointer is 4 bytes. If the system is 64-bit, size of void pointer is 8 bytes.Here is an example to find the size of void pointer in C language, Example Live Demo#include int main() {    void *ptr;    printf("The size of pointer value : %d", sizeof(ptr));    return 0; }OutputThe size of pointer value : 8In the above example, a void type pointer variable is created and by using sizeof() ... Read More

malloc() vs new() in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 07:45:24

5K+ Views

malloc()The function malloc() is used to allocate the requested size of bytes and it returns a pointer to the first byte of allocated memory. It returns null pointer, if fails.Here is the syntax of malloc() in C++ language, pointer_name = (cast-type*) malloc(size);Here, pointer_name − Any name given to the pointer.cast-type − The datatype in which you want to cast the allocated memory by malloc().size − Size of allocated memory in bytes.Here is an example of malloc() in C language, Example Live Demo#include #include int main() {    int n = 4, i, *p, s = 0;    p = ... Read More

fgets() and gets() in C

Samual Sam
Updated on 26-Jun-2020 07:46:12

1K+ Views

fgets()The function fgets() is used to read the string till the new line character. It checks array bound and it is safe too.Here is the syntax of fgets() in C language, char *fgets(char *string, int value, FILE *stream)Here, string − This is a pointer to the array of char.value − The number of characters to be read.stream − This is a pointer to a file object.Here is an example of fgets() in C language, Example Live Demo#include #define FUNC 8 int main() {    char b[FUNC];    fgets(b, FUNC, stdin);    printf("The string is: %s", b);    return 0; }OutputThe ... Read More

What should main() return in C/C++?

karthikeya Boyini
Updated on 26-Jun-2020 07:46:45

5K+ Views

The return value of main() function shows how the program exited. The normal exit of program is represented by zero return value. If the code has errors, fault etc., it will be terminated by non-zero value.In C++ language, the main() function can be left without return value. By default, it will return zero.Here is the syntax of main() function in C language, int main() {    ….    return 0; }Here is an example of main() function in C language, Example Live Demo#include int main() {    int a = 10;    char b = 'S';    float c = ... Read More

size_t data type in C

Samual Sam
Updated on 26-Jun-2020 07:47:14

8K+ Views

The datatype size_t is unsigned integral type. It represents the size of any object in bytes and returned by sizeof operator. It is used for array indexing and counting. It can never be negative. The return type of strcspn, strlen functions is size_t.Here is the syntax of size_t in C language, const size_t var_name;Here, var_name − This the name of variable.Here is an example of size_t in C language, Example Live Demo#include #include #include int main(void) {    const size_t x = 150;    int a[x];    for (size_t i = 0;i < x; ++i)    a[i] = ... Read More

Pointer Arithmetic in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 07:49:06

588 Views

Pointer arithmetic is used to implement arithmetic operations like addition subtraction, increment etc. in C language. There are four pointer arithmetic such as addition, subtraction, increment and decrement. In 32-bit machine, it increments or decrement the value by 2 and it will add or subtract 2* number. In 64-bit machine, it increments or decrement the value by 4 and it will add or subtract 4* number.Here is an example of pointer arithmetic in C language, Example Live Demo#include int main() {    int val = 28;    int *pt;    pt = &val;    printf("Address of pointer : %u", pt);   ... Read More

Advertisements