Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 467005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:32:14+00:00 2026-05-12T23:32:14+00:00

#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct dict_pair { void *key; void *value;

  • 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct dict_pair {
  void *key;
  void *value;
  struct dict_pair *tail;
} dict;


dict* NewDictionary(void) {
  dict *dictionary = malloc(sizeof(dict)); //or we can malloc(sizeof(struct dict_pair))
  dictionary->tail = NULL;
}

//dict operations
void put(dict *dictionary, void *key, void *value) {
  //new pair
  dict *new_pair = malloc(sizeof(dict));
  new_pair->key = key;
  new_pair->value = value;
  //chaining
  new_pair->tail = NULL;
  dict *last_node = dictionary;
  while (last_node->tail != NULL) {
    last_node = last_node->tail;
  }

  last_node->tail = new_pair;
}

void* get(dict *dictionary, void *key) {
  dict *current_dict = dictionary;
  while (1) {
    if (current_dict->key == key) {
      return current_dict->value;
    }
    else if (dictionary->tail != NULL) {
      current_dict = current_dict->tail;
    } else break;
  }
  return NULL;
}
//end operations

int main(void) {
  dict *dictionary = NewDictionary();
  put(dictionary,(void *) "buffer1",(void *) "Fake1");
  put(dictionary,(void *) "buffer2",(void *) "Fake2");
  put(dictionary,(void *) "key",(void *) "This is the value.");
  char *result = (char *) get(dictionary, (void *) "key");
  printf("%s\n",result);
}

So I managed to write the above code to implement a dictionary. While I was able to write the code and compile and get it to work expectedly, there are some stuff which I am not clear about. Mostly regarding pointers:

dict *current_dict = dictionary;

Lets take this line for example. We are declaring a variable which holds dict type. current_dict is a pointer, right? and dictionary is a pointer. However, *current_dict is not a pointer, how can it be assigned to a pointer?

Or do I have to explicitly type this to make it error?

dict (*current_dict) = dictionary;

If so, would this mean that the above line mean that we are declaring a current_dict variable with a dict type, and it is a pointer. Wouldnt that declaration be

(dict*) current_dict = dictionary;

As you can see, the spacing and positioning is confusing me.

Can someone help with explaining the difference in the * positioning?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:32:14+00:00Added an answer on May 12, 2026 at 11:32 pm

    While dict *dictionary and dict* dictionary have the same meaning in C, I prefer the former.

    I prefer to think of pointer declarations in these terms:

    int   x; //  x is an int
    int  *y; // *y is an int
    int **z; //**z is an int
    

    If you remember that *y is the object that y points to, then it follows that y must be a pointer-to-an-int. And similarly z must be a pointer-to-a-pointer-to-an-int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 218k
  • Answers 218k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's a field in the iTunes Connect app submission form… May 12, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer This might be what you are looking for : http://weston.ruter.net/2009/05/07/detecting-support-for-data-uris/… May 12, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer I've asked similar questions myself. There's a lot of room… May 12, 2026 at 11:32 pm

Related Questions

#include <stdio.h> #include <stdlib.h> int main() { FILE *fp = fopen(lr.txt, r); fseek(fp, 0L,
#include <stdio.h> #include <stdlib.h> #include <time.h> void initDeck (int deck[]); void showDeck (int deck[]);
#include <time.h> #include <stdio.h> #include <stdlib.h> char *czas() { time_t rawtime; struct tm *
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
If I include <stdlib.h> or <stdio.h> in a C program, I don't have to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.