Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to assign multiple values to multiple variables in one line with C

3 Answers

0 votes
#include <stdio.h>

int main() {
    int a, b, c, d;
    
    a = 1, b = 2, c = 3, d = 4; 
    
    printf("%d %d %d %d", a, b, c, d);

    return 0;
}


/*
run:

1 2 3 4

*/

 



answered Jul 14, 2025 by avibootz
0 votes
#include <stdio.h>

int main() {
    int values[] = {1, 2, 3, 4};
    
    int a = values[0], b = values[1], c = values[2], d = values[3]; 

    printf("%d %d %d %d", a, b, c, d);

    return 0;
}


/*
run:

1 2 3 4

*/

 



answered Jul 14, 2025 by avibootz
0 votes
#include <stdio.h>

struct Variables {
    int a, b, c, d;
};


int main() {
    struct Variables var = {1, 2, 3, 4}; // Initialize struct with values
    
    int a = var.a, b = var.b, c = var.c, d = var.d;  

    printf("%d %d %d %d", a, b, c, d);

    return 0;
}


/*
run:

1 2 3 4

*/

 



answered Jul 14, 2025 by avibootz
...