Virtual Shorting Using array of Pointer in c

09 Dec 2022 Balmiki Mandal 0 C Programming

What is an array of pointers in c

Virtual shorting using an array of pointers is a technique used in C programming to simulate a circuit diagram that includes multiple electrical connections to the same node, which would result in a short circuit in a physical circuit. In this technique, we use an array of pointers to represent the different nodes in the circuit, where each pointer points to the node's voltage value.

To simulate a short circuit, we simply assign the pointers of the nodes that are connected to the same point in the circuit to the same memory address. This effectively connects the nodes together, causing their voltage values to be equal. We can then perform calculations on the voltage values as if they were physically shorted together.

Example: int  *p[ 5 ]

p is an array of 5 Integers Pointers

Write a C Program for Virtual Shorting

#include<stdio.h>
#include<stdlib.h>
void main()
{
    char s[5][10],*t;
    char *p[5];
    int ele,i,j;
    ele=sizeof(s)/sizeof(s[0]);
    for(i=0;i<ele;i++)
    p[i]=s[i];
    printf("Enter the  5 String:");
    for(i=0;i<ele;i++)
    scanf("%s",s[i]);
    printf("\nBefore shorting Using array:");
    for(i=0;i<ele;i++)
    printf(" %s",s[i]);
    printf("\n Before Shorting Using Pointer:");
    for(i=0;i<ele;i++)
    printf(" %s",p[i]);
    for(i=0;i<ele-1;i++)
    {
        for(j=0;j<ele-1-i;j++)
        {
            if(strcmp(p[j],p[j+1])>0)
            {
                t=p[j];
                p[j]=p[j+1];
                p[j+1]=t;
            }
        }
    }
    printf("\n");
    printf("\nAfter shorting Using array:");
    for(i=0;i<ele;i++)
    printf(" %s",s[i]);
    printf("\n After Shorting Using Pointer:");
    for(i=0;i<ele;i++)
    printf(" %s",p[i]);
    printf("\n");
}

Output:

Enter the  5 String: mnop efgh wxyz abcd ijkl
Before shorting Using array: mnop efgh wxyz abcd ijkl
Before Shorting Using Pointer: mnop efgh wxyz abcd ijkl
After shorting Using array: mnop efgh wxyz abcd ijkl
After Shorting Using Pointer: abcd efgh ijkl mnop wxyz

Further Reading:


What is Array of pointer? Give one example.

Array of Pointer in c programming language

How to Create An Array Of Pointers in C – A Step-by-Step Guide

What is the difference between Array of pointer and Pointer to Array?

array of pointers, string functions, data manipulation, efficient algorithms

Dynamically Allocating Memory for an Array of Pointers

Virtual Shorting Using an array of Pointer

Write a C function that takes an array of pointers to strings and sorts them in lexicographic (dictionary) order.

 Assignment of Array of Pointers in C

Enroll Now:

C-Programming From Scratch to Advanced 2023-2024] "Start Supercharging Your Productivity!"

Contact Us:

  • For any inquiries, please email us at [[email protected]].
  • Follow us on insta  [ electro4u_offical_ ] for updates and tips.

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.