C++ e C: Suas diferenças básicas


A biblioteca padrão do C++ incorpora a biblioteca padrão do C com algumas pequenas modificações para trabalhar melhor com as novas funcionalidades criadas pela linguagem, tanto em C como em C++, os módulos da biblioteca são acessadas utilizando a diretiva #include. É importante destacar que a biblioteca padrão do C é a stdio.h enquanto a do C++ é a iostream.h, notaremos que a maneira como é implementada a impressão na tela e a obtenção de informações do teclado serão diferentes. Abaixo encontraremos o famoso “Hello Word”, impressão de uma mensagem na tela, para compreendermos melhor as diferenças entre eles.

Em C++

#include <iostream.h>

void main()
{
    cout << "Hello word!";
}
Em C
#include <stdio.h>

void main()
{
    printf("Hello word!");
}
A seguir iremos ver um exemplo de como capturar informações através do teclado:

Em C++
#include <iostream.h>

void main()
{
    int Valor;
    cout << "Porfavor digite um valor numerico a seguir: ";
    cin >> Valor;
}
Em C
#include <stdio.h>

void main()
{
    int Valor;
    printf("Porfavor digite um valor numerico a seguir: ");
    scanf("%i", &Valor);
}

Liked this article? Then leave a comment, follow this blog and subscribe to our RSS feed. Questions, problems, suggestions or translations? Please contact us. Click here for more instructions to make a small donation.

Be the first to comment

All comments are read and moderated before published.

For every comment
- ALL CAPS or grammatical errors will not be tolerated;
- Do not promote other blogs or websites;
- Do not add unnecessary links in the content of your comment;
- If you want to leave your URL, use the OpenID;
- Promote your e-mail only if really needed;
- Threats, insults or attacks are not allowed;
- Your comment must be related to the subject of the article;

Questions?
- Read all the answers;
- Ask if you can not find the answer;

Comments should contain only the following topics:
- Questions;
- Suggestions;
- Thanks;
- Tips related;

Every comment is a personal opinion of the reader. The authors are not responsible for the content of any comments made by the commenter(s). The authors are also not responsible for knowing whether the content of Your comment is breaking the law in other countries or jurisdictions.

  ©Template by Dicas Blogger and customized by Gugatb.

TOP