background preloader

C++

Facebook Twitter

C в примери - Грег Пери. Практическото ръководство за С от хитовия автор Грег Пери, написал над 60 учебника с повече от 2 милиона тираж!

C в примери - Грег Пери

Научете се да програмирате на C по лесния начин, чрез стотици тествани в клас практически примери. Покрива всичко – от основите на C до теми за напреднали, включително прототипи, работа с файлове, указатели. Безплатен сорс код. Можете да свалите пълния сорс код на всички примерни в книгата от адрес: Серията В примери е проектирана да обучи начинаещи и средно напреднали компютърни потребители да използват езици за програмиране чрез реални ситуации и примери. Главите включват: съветизабележкипредупрежденияпрепраткирезюмета, предаващи в перспектива информацията от главатаПоследната глава ви предоставя изцяло работеща програма, която сте изучавали в книгата и демонстрира концепциите, на които сте били обучавани във всяка от предходните глави.

Ръководство по програмиране. Стековете са известни още като LIFO - Last Input First Output.

Ръководство по програмиране

Стекът е такава структура, при която броят на елементите е краен, но е променлив. Съществува и стекове без елементи - празни стекове. Стек от елементи от тип Т (където Т е определен тип примерно int,char,float и тн.) е крайна (евентуално празна) редица от елементи от типа Т, с които могат да е изпълняват следните функции: 1. Достъп единствено до елемента, намиращ се в единия край на редицата (за определеност десния).

Стековете са линейни структури от данни. Основни операции за работа със стекове от тип Т. Debugging Strategies, Tips, and Gotchas. Debugging can be tedious and painful if you don't set up your programs to help you debug them.

Debugging Strategies, Tips, and Gotchas

In the spirit of "an apple a day keeps the doctor away", this article suggests approaches to writing code that's more debuggable, how to catch problems before they start, and gives you some time-wasting gotchas to watch out for and gives you some gotchas to watch out for. Use the Right Tools It should go without saying that you should always be using the best tools available; if you're hunting a segmentation fault, you want use a debugger.

Anything less than that is unnecessary pain. If you're dealing with bizarre memory issues (or hard-to-diagnose segfaults), use Valgrind on Linux or Purify for Windows. Debug the Problem My first instinct when debugging is to ask, "is my code too complicated? " The trick is always to decide if you're trying to solve the original problem or to solve a particular choice of solution. An Aside on Bad Code Minimize Potential Problems by Avoiding Copy-Paste Syndrome. Dealing with Compiler and Linker Errors. It's your first C (or C++) program--it's not that long, and you're about to compile it.

Dealing with Compiler and Linker Errors

You hit compile (or enter the build command) and wait. Your compiler spits out fifty lines of text. You pick out words like "warning and "error". Does that mean it worked? You wonder. The Types of Compilation Errors First, let's distinguish between the types of errors: most compilers will give three types of compile-time alerts: compiler warnings, compiler errors, and linker errors. Although you don't want to ignore them, compiler warnings aren't something severe enough to actually keep your program from compiling. Classes in C. C++ is a bunch of small additions to C, with a few major additions.

Classes in C

One major addition is the object-oriented approach (the other addition is support for generic programming, which we'll cover later). As the name object-oriented programming suggests, this approach deals with objects. Of course, these are not real-life objects themselves. Instead, these objects are the essential definitions of real world objects. Classes are collections of data related to a single object type. If a class is a house, then the functions will be the doors and the variables will be the items inside the house. The syntax for these classes is simple. Let's look at these different access restrictions for a moment. Classes must always contain two functions: a constructor and a destructor. When the programmer declares an instance of the class, the constructor will be automatically called. C++ Inheritance. The ability to use the object-oriented programming is an important feature of C++.

C++ Inheritance

Lesson 12: classes in C++ introduced the idea of the class; if you have not read it and do not know the basic details of classes, you should read it before continuing this tutorial. Inheritance is an important feature of classes; in fact, it is integral to the idea of object oriented programming. Inheritance allows you to create a hierarchy of classes, with various classes of more specific natures inheriting the general aspects of more generalized classes. In this way, it is possible to structure a program starting with abstract ideas that are then implemented by specific classes.

For example, you might have a class Animal from which class dog and cat inherent the traits that are general to all animals; at the same time, each of those classes will have attributes specific to the animal dog or cat. Inheritance offers many useful features to programmers. Classes, of course, share data. C/C++ уроци. Електронен сборник Pascal/C++