title: Assigning a really big number to a variable with GMP in C
body: <p>I'm currently learning about GMP in a course about scientific programming. I need to print the table of 23^45. This is a unusual big number, so I need to work with GMP.</p>
  <p>I have to problem with constructing a loop from 1 to 10. The trouble lies in assingning 23^45 to a variable. I searched for it online, but I couldn't find anything simillar.</p>
  <p>So far I know that first the mpz_t variables need to be defined. Then memory needs to be allocated for the variable. The next step is to assign the values to the variables.</p>
  <p>I already read this documentation:
  <a href="https://tspiteri.gitlab.io/gmp-mpfr-sys/gmp/Integer-Functions.html" rel="nofollow noreferrer">https://tspiteri.gitlab.io/gmp-mpfr-sys/gmp/Integer-Functions.html</a></p>
  <p>Therefore I know that I can assign a value with mpz_set_str(variable, &quot;str&quot;, base)</p>
  <p>or with mpz_set_d(variable, value to assign).</p>
  <p>So far I have:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;gmp.h&gt;
  #include &lt;math.h&gt;
  
  int main(void)
  {
  
     mpz_t a,b;
  
  
     // allocate memory for the variables
     mpz_init(a);
     mpz_init(b);
  </code></pre>
  <p>I want to achieve something like this:</p>
  <pre><code>// assign values
      
  mpz_set_d(a,pow(23,45));
  mpz_set_str(b,&quot;pow(23,45)&quot;,10)
  </code></pre>
  <p>From here I'm confused and I haven't been able to find an example. It would be great if anybody could help me or direct me to a simmilar thread.</p>
  <p>Ter</p>
  <p>UPDATE:</p>
  <p>I now have this piece of code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;gmp.h&gt;
  #include &lt;math.h&gt;
  
  int main(void)
  {
  
     mpz_t a,b,c,d;
  
     mpz_init(c);
  
     mpz_init_set_ui(a,23);
     mpz_init_set_ui(b,45);
  
     mpz_pow_ui(c,a,b);
  
     gmp_printf(&quot;a: %Zd , b: %Zd, 23^45: %Zd&quot;,a,b,c);
  
  
  
  
  
     return EXIT_SUCCESS;
  }
  </code></pre>
  <p>But I'm still not there, since I have a overflow.</p>
  <p>Question: Why do I get a overflow
  Question: What do I need to change in order to avoid the overflow?</p>