Isnt it possible to do something like following in Solidity? ps: i am taking example of "C" thinking it is somewhat similar to solidity. Correct me if i am wrong

#include <stdio.h>
struct student
    char name[50];
    int roll;

void display(struct student stu);
// function prototype should be below to the structure declaration otherwise compiler shows error

int main()
    struct student stud;
    printf("Enter student's name: ");
    scanf("%s", &stud.name);
    printf("Enter roll number:");
    scanf("%d", &stud.roll);
    display(stud);   // passing structure variable stud as argument
    return 0;
void display(struct student stu){
  printf("Output\nName: %s",stu.name);
  printf("\nRoll: %d",stu.roll);

You can't run the contract and prompt for data entry in the same way, but you can write getter/setter functions to pass in the values for vaiables (or declare a var as public as I think this automatically creates a getter & setter in the compiler).

printf isn't something you'd use either, since there's nowhere to print to. You're only setting the values in the contract and/or reading them. Printing them out you'd do in a front end or something via web3.

But create a struct? Yes. Pass in values and update vars? Yes. Extract variable values? yes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.