Pass Address of Structure as Argument to Function in C

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

584 Views

Passing the address of structure as an argument to function −The Address of the structure is passed as an argument to the function.It is collected in a pointer to structure in function header.AdvantagesNo wastage of memory as there is no need of creating a copy againNo need of returning the values back as the function can access indirectly the entire structure and work on it.Example#include struct date{    int day;    int mon;    int yr; }; main (){    struct date d= {02, 01, 2010};    display (&d);    getch (); } display (struct date *dt){    printf("day = ... Read More

Pass Individual Members of Structure as Arguments to Function in C

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

1K+ Views

Passing individual members as arguments to function −Each member is passed as an argument in the function call.They are collected independently in ordinary variables in function header.Example#include //Declaring structure// struct student{    int s1,s2,s3; }s[5]; //Declaring and returning Function// void addition(int a,int b,int c){    //Declaring sum variable and For loop variable//    int i,sum;    //Arithmetic Operation//    for(i=1;i

Pass Entire Structure as Argument to Function in C Language

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

910 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

Explain Structures Using typedef Keyword in C Language

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

579 Views

Typedef‘C’ allows to define new datatype names using the ‘typedef’ keyword. Using ‘typedef’, we cannot create a new datatype but define a new name for already existing type.Syntaxtypedef datatype newname;Exampletypedef int bhanu; int a; bhanu a; %dThis statement tells the compiler to recognize ‘bhanu’ as another name for ‘int’.‘bhanu’ is used to create another variable ‘a’ .‘bhanu a ‘declares ‘a’ as a variable of type ‘int’.Example#include main (){    typedef int hours;    hours h; //int h;    clrscr ();    printf("Enter hours”);    scanf ("%d”, &h);    printf("Minutes =%d”, h*60);    printf("Seconds = %d”, h*60*60);    getch (); ... Read More

Declaring a Structure with No Members in C Language

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

1K+ 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

Create Customized ATOI Function in C Language

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

195 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

793 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]

Character Analysis Function Explained with C Program

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

263 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

Convert Uppercase to Lowercase in C Without String Convert Function

Bhanu Priya
Updated on 09-Mar-2021 08:57:45

10K+ Views

Before going to know about how to convert upper case to lower case letters without string convert function.Let us have a look on program to convert upper to lower using convert function, then you will get a clarity on what we are doing in the program −Example#include #include int main(){    char string[50];    printf("enter a string to convert to lower case");    gets(string); /reading the string    printf("The string in lower case: %s", strlwr(string)); //strlwr converts all upper    to    lower    return 0; }Outputenter a string to convert to lower case CProgramming LangUage The string ... Read More

C Program Demonstrating strlen Library Function

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

304 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