write a c program to allocate dynamic memory for three string scan it and print it
BM Balmiki Mandal 16 Dec 2022 3 views 0 comments C Programming

write a c program to allocate dynamic memory for three string scan it and print it

"Write a C program to allocate dynamic memory for three strings, scan them, and print them" means to write a program in the C programming language that performs the following tasks:

  1. Dynamically allocate memory for three strings: This means that the program should request memory space from the operating system at runtime to store three strings.

  2. Scan the three strings: This means that the program should prompt the user to input three strings and store them in the memory space allocated in step 1.

  3. Print the three strings: This means that the program should retrieve the three strings stored in the memory space allocated in step 1 and print them to the console.

Overall, this program should demonstrate how to allocate dynamic memory in C, how to scan user input for three strings, and how to print the three strings to the console.

c program to allocate dynamic memory for three strings scan it and print it

#include<stdio.h>
#include<stdlib.h>
void main()
{
    char *p[3];
    int i;
    for (i=0;i<3;i++)
    p[i]=malloc(sizeof(char)*10);
    printf("Enter the String:");
    for(i=0;i<3;i++)
    scanf("%s",p[i]);
    for(i=0;i<3;i++)
    printf("%s\n",p[i]);   
}

Output:

Enter the String: Electro4u is Best

Electro4u is   Best

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026