Found 1401 Articles for C

Strings in C Language

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

1K+ Views

String is an array of characters and terminated by a null character (\0). The null character is not placed by the user, the compiler places it at the end of string automatically.The difference between an array and a string is that the compiler does not place null character at the end of array while in string, compiler places null character.Here is the syntax of string in C language, char myStr[size];Here, myStr: The stringsize: Set the size of stringInitialize string in C language like show below −char myStr[size] = “string”; char myStr[size] = { ‘s’, ’t’, ’r’, ’i’, ’n’, ’g’, ’\0’ ... Read More

Arrays in C Language

karthikeya Boyini
Updated on 24-Jun-2020 11:12:39

855 Views

Array is a collection of same type of elements at contiguous memory location. The lowest address corresponds to the first element while highest corresponds to last element.Array index starts with zero(0) and ends with the size of array minus one(array size - 1). Array size must be integer greater than zero.Let us see an example, If array size = 10 First index of array = 0 Last index of array = array size - 1 = 10-1 = 9Here is the syntax of arrays in C language, type array_name[array_size ];The following is how you can initialize an array.type array_name[array_size] = ... Read More

Convert a String to Uppercase in C

Samual Sam
Updated on 04-Oct-2023 14:05:42

28K+ Views

Here is the program to convert a string to uppercase in C language,Example#include #include int main() {    char s[100];    int i;    printf("Enter a string : ");    gets(s);    for (i = 0; s[i]!='\0'; i++) {       if(s[i] >= 'a' && s[i] = 'a' && s[i]

For Versus While Loop in C

karthikeya Boyini
Updated on 24-Jun-2020 11:13:48

380 Views

For LoopThe for loop is a repetition control structure. It executes the statements a specific number of times. First, it takes the initial value from where it starts the iterations. Second, it takes the condition, which is checked for true, or false. At the end, it increment/ decrement and update the loop variables.Here is the syntax of for loop in C language,for ( init; condition; increment ) {    statement(s); }Here is an example of for loop in C language,Example Live Demo#include int main () {    int a = 5;    for(int i=0;i

Float and Double in C

karthikeya Boyini
Updated on 02-Sep-2023 14:14:10

52K+ Views

FloatFloat is a datatype which is used to represent the floating point numbers. It is a 32-bit IEEE 754 single precision floating point number (1-bit for the sign, 8-bit for exponent, 23*-bit for the value. It has 6 decimal digits of precision.Here is the syntax of float in C language, float variable_name;Here is an example of float in C language, Example Live Demo#include #include int main() {    float x = 10.327;    int y = 28;    printf("The float value : %f", x);    printf("The sum of float and int variable : %f", (x+y));    return 0; }OutputThe float value ... Read More

strcmp() in C/C++

Samual Sam
Updated on 24-Jun-2020 11:06:18

27K+ Views

The function strcmp() is a built-in library function and it is declared in “string.h” header file. This function is used to compare the string arguments. It compares strings lexicographically which means it compares both the strings character by character. It starts comparing the very first character of strings until the characters of both strings are equal or NULL character is found.If the first character of both strings are equal, it checks second character and so on. This process will be continued until NULL character is found or both characters are unequal.Here is the syntax of strcmp() in C language, int ... Read More

strcpy() in C/C++

karthikeya Boyini
Updated on 24-Jun-2020 11:06:39

4K+ Views

The function strcpy() is a standard library function. It is used to copy one string to another. In C language, it is declared in “string.h” header file while in C++ language, it is declared in cstring header file. It returns the pointer to the destination.Here is the syntax of strcpy() in C language, char* strcpy(char* dest, const char* src);Some key points of strcpy().It copies the whole string to the destination string. It replaces the whole string instead of appending it.It won’t change the source string.Here is an example of strcpy() in C language, Example Live Demo#include #include int main() { ... Read More

Difference between getc(), getchar(), getch() and getche()

Samual Sam
Updated on 24-Jun-2020 11:07:13

4K+ Views

All these functions read the character from input and return an integer. The value of EOF is used for this purpose.getc()It reads a single character from the input and return an integer value. If it fails, it returns EOF.Here is the syntax of getc() in C language, int getc(FILE *stream);Here is an example of getc() in C language, Example Live Demo#include int main () {    char val;    printf("Enter the character: ");    val = getc(stdin);    printf("Character entered: ");    putc(val, stdout);    return(0); }OutputEnter the character: a Character entered: agetchar()The function getchar() reads the character from the standard ... Read More

printf(), sprintf() and fprintf() in C

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

3K+ Views

printf()The function printf() is used to print the message along with the values of variables.Here is the syntax of printf() in C language, printf(const char *str, ...);Here is an example of printf() in C language, Example Live Demo#include int main() {    int a = 24;    printf("Welcome! ");    printf("The value of a : %d", a);    getchar();    return 0; }OutputWelcome! The value of a : 24sprintf()The function sprintf() is also known as string print function. It do not print the string. It stores the character stream on char buffer. It formats and stores the series of characters and ... Read More

How to print % using printf()?

Samual Sam
Updated on 24-Jun-2020 11:08:21

4K+ Views

Generally, printf() function is used to print the text along with the values. If you want to print % as a string or text, you will have to use ‘%%’. Neither single % will print anything nor it will show any error or warning.Here is an example to print % in printf() in C language, Example Live Demo#include int main() {    printf("%");    printf("%%");    getchar();    return 0; }Output%There are some other ways to print % in the text message as in the following example, Example Live Demo#include #include int main() {    printf("welcome%");    printf("%%");    printf("%c", '%');   ... Read More

Advertisements