<!DOCTYPE html>
<html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-menu-disabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-0 vector-toc-not-available vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-0 skin-theme-clientpref-os vector-sticky-header-enabled skin-theme-clientpref-thumb-standard" lang="pt" dir="ltr"><head>
    <meta charset="UTF-8">
    <title>Stdlib.h</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/png" href="./_res_/favicon.png">
    <link rel="canonical" href="https://pt.wikipedia.org/wiki/Stdlib.h"> <link href="./_mw_/ext.wikimediamessages.styles.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/mediawiki.skinning.content.parsoid.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/skins.vector.icons.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
    <link href="./_mw_/skins.vector.styles.css" rel="stylesheet" type="text/css">
    <meta name="ResourceLoaderDynamicStyles" content="">
    <link href="./_mw_/ext.gadget.keepPDU.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="./_mw_/site.styles.css">
    <link rel="stylesheet" type="text/css" href="./_mw_/noscript.css">
    <link rel="stylesheet" type="text/css" href="./_res_/footer.css">
    <link rel="stylesheet" type="text/css" href="./_res_/vector-2022.css">
  </head>
  <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Stdlib_h rootpage-Stdlib_h skin-vector-2022 action-view">
    <div class="mw-page-container">
      <div class="mw-page-container-inner">
        <div class="mw-content-container">
          <main id="content" class="mw-body">
            <header class="mw-body-header vector-page-titlebar">
              <h1 id="firstHeading" class="firstHeading mw-first-heading">stdlib.h</h1>
            </header>
            <a id="top"></a>
            <div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
              <div id="contentSub">
                <div id="mw-content-subtitle"></div>
              </div>
              <div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="pt" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="pt" dir="ltr" data-mw-parsoid-version="0.24.0.0-alpha2" data-mw-html-version="2.8.0"><section data-mw-section-id="0" id="mwAQ"><span typeof="mw:Transclusion" id="mwAg"></span>
<table class="infobox" style="text-align: center; font-size:90%;" typeof="mw:Transclusion" id="mwAw">
<tbody><tr><td style="text-align: center;"><b><a rel="mw:WikiLink" href="Biblioteca_padr%C3%A3o_do_C" title="Biblioteca padrão do C">Biblioteca padrão do C</a></b></td></tr>
<tr>
<td style="text-align: left;">
<ul><li><a rel="mw:WikiLink" href="Assert.h" title="Assert.h">assert.h</a></li>
<li><a rel="mw:WikiLink" href="Complex.h" title="Complex.h">complex.h</a></li>
<li><a rel="mw:WikiLink" href="Ctype.h" title="Ctype.h">ctype.h</a></li>
<li><a rel="mw:WikiLink" href="Errno.h" title="Errno.h">errno.h</a></li>
<li>fenv.h</li>
<li><a rel="mw:WikiLink" href="Float.h" title="Float.h">float.h</a></li>
<li>inttypes.h</li>
<li><a rel="mw:WikiLink" href="Iso646.h" title="Iso646.h">iso646.h</a></li>
<li><a rel="mw:WikiLink" href="Limits.h" title="Limits.h">limits.h</a></li>
<li><a rel="mw:WikiLink" href="Locale.h" title="Locale.h" class="mw-redirect">locale.h</a></li>
<li><a rel="mw:WikiLink" href="Math.h" title="Math.h">math.h</a></li>
<li><a rel="mw:WikiLink" href="Setjmp.h" title="Setjmp.h">setjmp.h</a></li>
<li><a rel="mw:WikiLink" href="Signal.h" title="Signal.h">signal.h</a></li>
<li><a rel="mw:WikiLink" href="Stdarg.h" title="Stdarg.h">stdarg.h</a></li>
<li><a rel="mw:WikiLink" href="Stdbool.h" title="Stdbool.h">stdbool.h</a></li>
<li><a rel="mw:WikiLink" href="Stddef.h" title="Stddef.h">stddef.h</a></li>
<li><a rel="mw:WikiLink" href="Stdint.h" title="Stdint.h">stdint.h</a></li>
<li><a rel="mw:WikiLink" href="Stdio.h" title="Stdio.h">stdio.h</a></li>
<li><a rel="mw:WikiLink" href="Stdlib.h" class="mw-selflink selflink">stdlib.h</a></li>
<li><a rel="mw:WikiLink" href="String.h" title="String.h">string.h</a></li>
<li><a rel="mw:WikiLink" href="Tgmath.h" title="Tgmath.h" class="mw-redirect">tgmath.h</a></li>
<li><a rel="mw:WikiLink" href="Time.h" title="Time.h">time.h</a></li>
<li><a rel="mw:WikiLink" href="Wchar.h" title="Wchar.h" class="mw-redirect">wchar.h</a></li>
<li><a rel="mw:WikiLink" href="Wctype.h" title="Wctype.h" class="mw-redirect">wctype.h</a></li></ul></td></tr>

</tbody></table>
<p id="mwBA"><b id="mwBQ">Stdlib.h</b> é um arquivo cabeçalho da <b id="mwBg">biblioteca de propósito geral padrão</b> da linguagem de programação <a rel="mw:WikiLink" href="C_(linguagem_de_programa%C3%A7%C3%A3o)" title="C (linguagem de programação)" id="mwBw">C</a>. Ela possui funções envolvendo alocação de memória, controle de processos, conversões e outras. Ela é compatível com <a rel="mw:WikiLink" href="C%2B%2B" title="C++" id="mwCA">C++</a> e é chamada <code id="mwCQ">cstdlib</code> em <a rel="mw:WikiLink" href="C%2B%2B" title="C++" id="mwCg">C++</a>. O nome "stdlib" vem de <b id="mwCw">standard</b> <b id="mwDA">lib</b>rary (standard library é biblioteca padrão em inglês).</p>

</section><section data-mw-section-id="1" id="mwDg" aria-labelledby="Funções_membros"><div class="mw-heading mw-heading2"><h2 id="Funções_membros"><span id="Fun.C3.A7.C3.B5es_membros" typeof="mw:FallbackId"></span>Funções membros</h2></div>

<p id="mwDw">Membros de <code id="mwEA">stdlib.h</code> pode ser classificado em: conversão, memória, controle de processo, ordenamento e busca, matemática.</p>

<table class="wikitable" id="mwEQ">
<tbody id="mwEg"><tr id="mwEw">
<th id="mwFA">Name</th><th id="mwFQ">Description</th></tr>
<tr id="mwFg">
<th colspan="2" id="mwFw">Conversão de tipo</th></tr>
<tr id="mwGA">
<td id="mwGQ"><code id="mwGg">atof</code></td><td id="mwHA">string para float</td></tr>
<tr id="mwHQ">
<td id="mwHg"><code id="mwHw"><a rel="mw:WikiLink" href="Atoi" title="Atoi" id="mwIA">atoi</a></code></td><td id="mwIQ">string para integer</td></tr>
<tr id="mwIg">
<td id="mwIw"><code id="mwJA">atol</code></td><td id="mwJg">string para long integer</td></tr>
<tr id="mwJw">
<td id="mwKA"><code id="mwKQ">strtod</code></td><td id="mwKw">string para double</td></tr>
<tr id="mwLA">
<td id="mwLQ"><code id="mwLg"><a rel="mw:WikiLink" href="Strtol" title="Strtol" id="mwLw">strtol</a></code></td><td id="mwMA">string para long int</td></tr>
<tr id="mwMQ">
<td id="mwMg"><code id="mwMw">strtoul</code></td><td id="mwNQ">string para unsigned long int</td></tr>
<tr id="mwNg">
<th colspan="2" id="mwNw">Geração de seqüência pseudo-aleatória</th></tr>
<tr id="mwOA">
<td id="mwOQ"><code id="mwOg"><a rel="mw:WikiLink" href="Rand" title="Rand" id="mwOw">rand</a></code></td><td id="mwPA">gera um número inteiro pseudo aleatório</td></tr>
<tr id="mwPQ">
<td id="mwPg"><code id="mwPw">srand</code></td><td id="mwQQ">seleciona a semente do gerador pseudo aleatório</td></tr>
<tr id="mwQg">
<th colspan="2" id="mwQw">Alocação e liberação de memória</th></tr>
<tr id="mwRA">
<td id="mwRQ"><code id="mwRg"><a rel="mw:WikiLink" href="Malloc" title="Malloc" class="mw-redirect" id="mwRw">malloc</a></code><br id="mwSA"><code id="mwSQ"><a rel="mw:WikiLink" href="Calloc" title="Calloc" class="mw-redirect" id="mwSg">calloc</a></code><br id="mwSw"><code id="mwTA">realloc</code></td><td id="mwTg">aloca memória do "heap"</td></tr>
<tr id="mwTw">
<td id="mwUA"><code id="mwUQ"><a rel="mw:WikiLink" href="Free" title="Free" class="mw-disambig" id="mwUg">free</a></code></td><td id="mwUw">libera memória de volta para o "heap"</td></tr>
<tr id="mwVA">
<th colspan="2" id="mwVQ">Controle de processos</th></tr>
<tr id="mwVg">
<td id="mwVw"><code id="mwWA">abort</code></td><td id="mwWg">força o término da execução</td></tr>
<tr id="mwWw">
<td id="mwXA"><code id="mwXQ">atexit</code></td><td id="mwXw">registra uma função "callback" para saída do programa</td></tr>
<tr id="mwYA">
<td id="mwYQ"><code id="mwYg">exit</code></td><td id="mwZA">termina a execução do programa</td></tr>
<tr id="mwZQ">
<td id="mwZg"><code id="mwZw">getenv</code></td><td id="mwaQ">obtém uma variável de ambiente</td></tr>
<tr id="mwag">
<td id="mwaw"><code id="mwbA"><a rel="mw:WikiLink" href="System" title="System" class="mw-disambig" id="mwbQ">system</a></code></td><td id="mwbg">executa um comando externo</td></tr>
<tr id="mwbw">
<th colspan="2" id="mwcA">Ordenamento e busca</th></tr>
<tr id="mwcQ">
<td id="mwcg"><code id="mwcw">bsearch</code></td><td id="mwdQ">busca binária em "array"</td></tr>
<tr id="mwdg">
<td id="mwdw"><code id="mweA">qsort</code></td><td id="mweg">ordena "array" segundo algoritmo Quick Sort</td></tr>
<tr id="mwew">
<th colspan="2" id="mwfA">Matemática</th></tr>
<tr id="mwfQ">
<td id="mwfg"><code id="mwfw"><a rel="mw:WikiLink" href="Abs" title="Abs" class="mw-redirect mw-disambig" id="mwgA">abs</a></code><br id="mwgQ"><code id="mwgg">labs</code></td><td id="mwhA"><a rel="mw:WikiLink" href="Valor_absoluto" title="Valor absoluto" class="mw-disambig" id="mwhQ">valor absoluto</a></td></tr>
<tr id="mwhg">
<td id="mwhw"><code id="mwiA">div</code><br id="mwig"><code id="mwiw">ldiv</code></td><td id="mwjQ">divisão inteira</td></tr>
</tbody></table>

</section><section data-mw-section-id="2" id="mwjg" aria-labelledby="Membros_constantes"><div class="mw-heading mw-heading2"><h2 id="Membros_constantes">Membros constantes</h2></div>
<p id="mwjw">Os arquivos <code id="mwkA">stdlib.h</code> e <code id="mwkQ">stddef.h</code> definem a macro <a rel="mw:WikiLink" href="Ponteiro_(programa%C3%A7%C3%A3o)#Ponteiro_nulo" title="Ponteiro (programação)" id="mwkg">NULL</a>, que é um ponteiro nulo constante, e representa um valor de ponteiro que garante não apontar para um endereço válido na memória. NULL pode ser definido como uma constante igual a int zero, long int zero, ou zero "cast" para void<span typeof="mw:Entity" id="mwkw">&nbsp;</span>* pointer:</p>

<p id="mwlA"><code id="mwlQ">#define NULL  0</code><br id="mwlg">
<code id="mwlw">#define NULL  0L</code><br id="mwmA">
<code id="mwmQ">#define NULL  ((void *) 0)</code></p>

<p id="mwmg">Nota: Apesar do ponteiro nulo constante ser definido sempre como a representação simbólica 0 ou 0 "cast" para ponteiro void, a representação binária real desse ponteiro é dependente de sistema e pode não ter todos os bits zero.</p>

</section><section data-mw-section-id="3" id="mwmw" aria-labelledby="Membros_do_tipo_de_dados"><div class="mw-heading mw-heading2"><h2 id="Membros_do_tipo_de_dados">Membros do tipo de dados</h2></div>
<p id="mwnA">Um tipo de dados chamado <code id="mwnQ">size_t</code> é definido em <code id="mwng">stdlib.h</code>, que representa o tamanho de um "array" na função membro. Na prática, <code id="mwnw">size_t</code> é sempre assumido ter os mesmos requisitos para armazenamento que um unsigned integer.  Devido ao fato de que o valor real de <code id="mwoA">size_t</code> é dependente de arquitetura, alguns erros de programação podem ocorrer, <a rel="mw:ExtLink nofollow" href="https://web.archive.org/web/20100104181809/http://www.gamedev.net/reference/programming/features/20issues64bit/" class="external autonumber" id="mwoQ"></a>, especialmente em  arquiteturas de 64 bits. </p>

<p id="mwog">Dois tipo de dados menos utilizados são <code id="mwow">div_t</code> e <code id="mwpA">ldiv_t</code>. Eles retornam os tipos de retorno das funções div e ldiv. O padrão as define como:</p>

<pre id="mwpw">typedef struct {
    int quot, rem;
} div_t;</pre>

<pre id="mwqA">typedef struct {
    long int quot, rem;
} ldiv_t;</pre>

</section><section data-mw-section-id="4" id="mwqQ" aria-labelledby="Funções_não_padronizadas"><div class="mw-heading mw-heading2"><h2 id="Funções_não_padronizadas"><span id="Fun.C3.A7.C3.B5es_n.C3.A3o_padronizadas" typeof="mw:FallbackId"></span>Funções não padronizadas</h2></div>
<p id="mwqg">itoa é uma função comum que é incluída várias vezes na biblioteca stdlib.h, mas o padrão não a define. Ela pode ter sido inclusa pelo fato de ter aparecido no livro <i id="mwrA"><a rel="mw:WikiLink" href="The_C_Programming_Language" title="The C Programming Language" id="mwrQ">The C Programming Language</a></i>.</p>

</section><section data-mw-section-id="5" id="mwrg" aria-labelledby="Veja_também"><div class="mw-heading mw-heading2"><h2 id="Veja_também"><span id="Veja_tamb.C3.A9m" typeof="mw:FallbackId"></span>Veja também</h2></div>
<p id="mwrw"><a rel="mw:WikiLink" href="Stdio.h" title="Stdio.h" id="mwsA">stdio.h</a></p>

</section><section data-mw-section-id="6" id="mwsQ" aria-labelledby="References"><div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<ul id="mwsg"><li id="mwsw"><a rel="mw:ExtLink nofollow" href="http://www.cplusplus.com/ref/cstdlib/" class="external text" id="mwtA">sumário de stdlib.h em cplusplus.com</a>, acessado em Fevereiro de 2006.</li></ul>



</section></div><!--htdig_noindex--><div><div class="zim-footer">
    Este artigo é emitido por <a class="external text" title="Última edição em 2019-05-23" href="https://pt.wikipedia.org/wiki/?title=Stdlib.h&amp;oldid=55248020">Wikipédia</a>. O texto é licenciado sob <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.pt">Creative Commons Attribution-Share Alike 4.0</a>. Termos adicionais podem ser aplicados aos arquivos de mídia.
</div>
</div><!--/htdig_noindex--></div>
            </div>
          </main>
        </div>
      </div>
    </div>
     <script src="./_webp_/webpHandler.js"></script>
  

</body></html>