Found 1452 Articles for C

calloc() versus malloc() in C

karthikeya Boyini
Updated on 26-Jun-2020 08:01:39

2K+ Views

calloc()The function calloc() stands for contiguous location. It works similar to the malloc() but it allocate the multiple blocks of memory each of same size.Here is the syntax of calloc() in C language, void *calloc(size_t number, size_t size);Here, number − The number of elements of array to be allocated.size − Size of allocated memory in bytes.Here is an example of calloc() in C language, Example Live Demo#include #include int main() {    int n = 4, i, *p, s = 0;    p = (int*) calloc(n, sizeof(int));    if(p == NULL) {       printf("Error! memory not allocated."); ... Read More

fgetc() and fputc() in C

Samual Sam
Updated on 26-Jun-2020 08:02:42

4K+ Views

fgetc()The function fgetc() is used to read the character from the file. It returns the character pointed by file pointer, if successful otherwise, returns EOF.Here is the syntax of fgetc() in C language, int fgetc(FILE *stream)Here is an example of fgetc() in C language, Let’s say we have “new.txt” file with the following content −0, hell!o 1, hello! 2, gfdtrhtrhrt 3, demoNow, let us see the example −Example#include #include void main() {    FILE *f;    char s;    clrscr();    f=fopen("new.txt", "r");    while((s=fgetc(f))!=EOF) {       printf("%c", s);    }    fclose(f);    getch(); }Here is the ... Read More

isgreaterequal() in C/C++

karthikeya Boyini
Updated on 26-Jun-2020 08:03:19

146 Views

The function isgreaterequal() is used to check that the first argument is greater than or equal to the second one. It is declared in “math.h” header file in C language. It returns true on success, otherwise false.Here is the syntax of islessgreater() in C++ language, bool isgreaterequal(value1 , value2);Here, value1 − This is the first argument which will be checked with value2.value2 − This is the second argument which is used to check value1 that is greater or equal.Here is an example of isgreaterequal() in C++ language, Example Live Demo#include #include using namespace std; int main() {    int val1 = ... Read More

strchr() function in C/C++

Samual Sam
Updated on 26-Jun-2020 08:03:47

272 Views

The function strchr() is used to search the character in the string. It search the first occurrence of character which is passed as second argument and it returns a pointer to the character, if successful otherwise, NULL.Here is the syntax of strchr() in C language, char *strchr(const char *string , int character)Here, string − The string which is to be scanned to search the character.character − The character which is to be searched in the string.Here is an example of strchr() in C language, Example Live Demo#include #include int main() {    char s[] = "Helloworld!";    char c = 'o'; ... Read More

Union in C

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

554 Views

Union is a user defined datatype. All the members of union share same memory location. Size of union is decided by the size of largest member of union. If you want to use same memory location for two or more members, union is the best for that.Unions are similar to the structure. Union variables are created in same manner as structure variables. The keyword “union” is used to define unions in C language.Here is the syntax of unions in C language, union union_name {    member definition; } union_variables;Here, union_name − Any name given to the union.member definition − Set ... Read More

Structures in C

Samual Sam
Updated on 26-Jun-2020 07:50:01

819 Views

Structure is a user defined datatype. It is used to combine the different types of data into single type. It can have multiple members and structure variables. The keyword “struct” is used to define structures in C language. Structure members can be accessed by using dot(.) operator.Here is the syntax of structures in C language, struct structure_name {    member definition; } structure_variables;Here, structure_name − Any name given to the structure.member definition − Set of member variables.structure_variable − This is the object of structure.Here is an example of structures in C language, Example Live Demo#include #include struct Data { ... Read More

Enum in C

karthikeya Boyini
Updated on 26-Jun-2020 07:50:44

10K+ Views

Enumeration is a user defined datatype in C language. It is used to assign names to the integral constants which makes a program easy to read and maintain. The keyword “enum” is used to declare an enumeration.Here is the syntax of enum in C language, enum enum_name{const1, const2, ....... };The enum keyword is also used to define the variables of enum type. There are two ways to define the variables of enum type as follows.enum week{sunday, monday, tuesday, wednesday, thursday, friday, saturday}; enum week day;Here is an example of enum in C language, Example Live Demo#include enum week{Mon=10, Tue, Wed, Thur, ... Read More

Comments in C/C++

Samual Sam
Updated on 26-Jun-2020 07:51:28

251 Views

Comments are the part of code which are ignored by the compiler. It makes the code easy to read and understand. Single and multi-line comments both work in the same way in C++ language.Comments in C/C++// Single Line Comment /* Multi Line Comments */Here is an example of comments in C language, Example Live Demo#include #include int main () {    /* declarations    of    data members */    char s[10] = "HelloWorld";    char d[10];    int n;    n = strxfrm(d, s, 5);    printf("Length of string : %d", n); // length of string   ... Read More

strxfrm() in C/C++

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

225 Views

The function strxfrm() transforms the source string to the current locale and copies the first number of characters of transformed string to the destination. It is declared in “locale.h” header file in C language.Here is the syntax of strxfrm() in C language, size_t strxfrm(char *destination, const char *source, size_t number)Here, destination − The destination pointer where the characters will be copied.source − The string is to be transformed.number − The number of characters to be copied.Here is an example of strxfrm() in C language, Example#include #include int main () has {    char s[10] = "HelloWorld";    char ... Read More

islessequal() in C/C++

Samual Sam
Updated on 26-Jun-2020 07:52:25

140 Views

The function islessequalr() is used to check that first argument is less than or equal to the second. It is declared in “math.h” header file. It returns true, if successful otherwise false.Here is the syntax of islessequal()bool islessequal(value1 , value2);Here, value1 − This is the first argument which will be checked with value2.value2 − This is the second argument which is used to check value1 that is less or equal.Here is an example of islessequal()Example Live Demo#include #include using namespace std; int main() {    int val1 = 8;    int val2 = 8;    bool result;    result = islessequal(val1, ... Read More

Advertisements