Found 1401 Articles for C

Explain the concept of Uninitialized array accessing in C language

Bhanu Priya
Updated on 09-Mar-2021 09:48:46

836 Views

ProblemIn C language, is the program executed, if we use an uninitialized array?SolutionIf we use any uninitialized array, compiler will not generate any compilation and an execution error.If an array is uninitialized, you may get unpredictable result.So, it’s better we should always initialize the array elements with default values.Example ProgramFollowing is the C program of accessing an uninitialized array − Live Demo#include int main(void){    int a[4];    int b[4] = {1};    int c[4] = {1,2,3,4};    int i; //for loop counter    //printing all alements of all arrays    printf("Array a:");    for( i=0; i

What is out of bounds index in an array - C language?

Bhanu Priya
Updated on 09-Mar-2021 09:46:45

2K+ Views

Suppose you have an array with four elements. Then, an array indexing will be from 0 to 3, i.e., we can access elements from index 0 to 3.But, if we use index which is greater than 3, it will be called as an index out of bounds.If, we use an array index which is out of bounds, then the compiler will compile and even run. But, there is no guarantee for the correct result.Result can be not sure and it will start causing many problems. Hence, it is advised to be careful while using an array indexing.Example ProgramFollowing is the ... Read More

What is an array of structures in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:44:42

1K+ Views

The most common use of structure in C programming language is an array of structures.To declare an array of structures, first the structure must be defined and then, an array variable of that type can be defined.For example, struct book b[10]; //10 elements in an array of structures of type ‘book’ExampleGiven below is the C program for accepting and printing details of 3 students with regards to an array of structures − Live Demo#include #include struct student{    int id;    char name[30];    float percentage; }; int main(){    int i;    struct student record[2];    // 1st ... Read More

How to pass entire structure as an argument to function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:37:28

791 Views

Passing entire structure as an argument to function −Name of the structure variable is given as argument in function call.It is collected in another structure variable in function header.DisadvantageA copy of the entire structure is created again wasting memoryProgramFollowing program demonstrates passing an entire structure as an argument to function − Live Demo#include //Declaring structure// struct add{    int var1;    int var2; }a; //Declaring and returning Function// void show(struct add a){    //Declaring sum variable//    int sum;    //Arithmetic Operation//    sum=a.var1+a.var2;    //Printing O/p//    printf("Added value is %d", sum); } void main(){    //Declaring structure//    struct ... Read More

Declaring a structure with no members in C language

Bhanu Priya
Updated on 09-Mar-2021 09:35:11

841 Views

ProblemCan we declare a structure with no members in C, if yes what will be the size of that structure?SolutionYes, it is allowed in C programming language that we can declare a structure without any member and in that case the size of the structure with no members will be 0 (Zero). It will be a Zero size structure.Example Live Demo#include //structure with no members struct temp{ }; int main(){    //declaring structure variable    struct temp T;    printf("Size of T: %d", sizeof(T));    return 0; }OutputIn this C program, we are declaring a structure named "temp" without declare ... Read More

What are nested structures in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:32:18

19K+ Views

Structure within structure (or) Nested structuresA structure inside another structure is called nested structure.Consider the following example, struct emp{    int eno;    char ename[30];    float sal;    float da;    float hra;    float ea; }e;All the items comes under allowances can be grouped together and declared under a sub – structure as shown below.stuct emp{    int eno;    char ename[30];    float sal;    struct allowance{       float da;       float hra;       float ea;    }a; }e;The inner most member in a nested structure can be accessed by changing ... Read More

How to create a customized atoi() function in C language?

Bhanu Priya
Updated on 09-Mar-2021 09:31:03

115 Views

The atoi() is predefined function used to convert a numeric string to its integer value.Create a customized atoi()The atoi() only converts a numeric string to integer value, so we need to check the validity of the string.If this function encounters any non-numeric character in the given string, the conversion from string to integer will be stopped.Example Live Demo#include #include #include int main(){    int value;    char string1[] = "3567";    value = atoi(string1);    printf("String value = %s", string1);    printf("Integer value = %d", value);    char string2[] = "TutorialsPoint";    value = atoi(string2);    printf("String value ... Read More

Finding number of alphabets, digits and special characters in strings using C language

Bhanu Priya
Updated on 09-Mar-2021 09:20:25

596 Views

Following is the logic we implement to find alphabets, digits and special characters −for(number=0;string[number]!='\0';number++) {// for loop until endof string    if(string[number]>='a'&&string[number]='A'&&string[number]='0'&&string[number]='a'&&string[number]='A'&&string[number]='0'&&string[number]

What are character analysis function, explain with C program?

Bhanu Priya
Updated on 09-Mar-2021 09:17:07

160 Views

Character analysis and conversion functionsThe predefined functions in “ctype.h” library is for analyzing the character input and converting them.Analysis functionsS.NoFunctionDescription1isalpha()An alphabet or not2isdigit()A digit or not3isspace()A space, a new line or tab4ispunct()A special symbol or not5slower()A lower case letter of alphabet6isupper()An upper case letter of alphabet7isalphanumeric()An alphabet/digit or notConverting functionsFunctionDescriptiontolower()Converts an upper case alphabet to lower casetoupper()Converts a lower case alphabet to upper caseExampleLet us see a program to demonstrate character analysis and conversion functions − Live Demo#include #include void main(){    //Initializing compile time character variable// char variable = 'A';    //Reading User I/P//    //printf("Enter the character : "); ... Read More

Write a C program demonstrating strlen library function

Bhanu Priya
Updated on 09-Mar-2021 08:56:47

208 Views

The strlen () functionIt returns the number of characters in a string.Syntaxint strlen (string name)In this program, with the help of gets function reading the name at run time and trying to print the length of that name using strlen() function, this function returns an integer value and try to print that no using printf.Example 1 Live Demo#include #include void main(){    //Declaring string and length//    char name[25];    int length;    //Reading Input from user//    printf("Enter your name : ");    gets(name);    length=strlen(name);    //Printing name//    printf("Your name is : ");    puts(name);    printf("Length of ... Read More

Advertisements