C++ Programming Basics
However to become proficient in any programming language, one Firstly needs to understand the basics of that language.
Therefore, below are the basics of C++ in the format in which it will help you the most to get the headstart:
- Basic Syntax and First Program in C++: Learning C++ programming can be simplified into writing your program in a text editor and saving it with correct extension(.CPP, .C, .CP) and compiling your program using a compiler or online IDE. The “Hello World” program is the first step towards learning any programming language and also one of the simplest programs you will learn.
- Basic I/O in C++:C++ comes with libraries which provides us with many ways for performing input and output. In C++ input and output is performed in the form of a sequence of bytes or more commonly known as streams. The two keywords cin and cout are used very often for taking inputs and printing outputs respectively. These two are the most basic methods of taking input and output in C++.
- Comments in C++: A well-documented program is a good practice as a programmer. It makes a program more readable and error finding become easier. One important part of good documentation is Comments. In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. These are statements that are not executed by the compiler and interpreter.
- Data Types and Modifiers in C++: All variables use data-type during declaration to restrict the type of data to be stored. Therefore, we can say that data types are used to tell the variables the type of data it can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data-type with which it is declared. Every data type requires a different amount of memory.
- Uninitialized variable in C++: “One of the things that has kept C++ viable is the zero-overhead rule: What you don’t use, you don’t pay for.” -Stroustrup. The overhead of initializing a stack variable is costly as it hampers the speed of execution, therefore these variables can contain indeterminate values. It is considered a best practice to initialize a primitive data type variable before using it in code.
- Undefined Behaviour in C++: If a user starts learning in C/C++ environment and is unclear with the concept of undefined behaviour then that can bring plenty of problems in the future like while debugging someone else code might be actually difficult in tracing the root to the undefined error.
- Variables and Types in C++: A variable is a name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. In C++, all the variables must be declared before use.
- Variable Scope in C++: In general, scope is defined as the extent up to which something can be worked with. In programming also the scope of a variable is defined as the extent of the program code within which the variable can be accessed or declared or worked with. There are mainly two types of variable scopes, Local and Global Variables.
- Constants and Literals in C++: As the name suggests the name constants is given to such variables or values in C++ programming language which cannot be modified once they are defined. They are fixed values in a program. There can be any types of constants like integer, float, octal, hexadecimal, character constants, etc. Every constant has some range. The integers that are too big to fit into an int will be taken as long. Now there are various ranges that differ from unsigned to signed bits. Under the signed bit, the range of an int varies from -128 to +127 and under the unsigned bit, int varies from 0 to 255. Literals are kind of constants and both the terms are used interchangeably in C++.
- Types of Literals in C++: In this article we will analyse the various kind of literals that C++ provides. The values assigned to each constant variables are referred to as the literals. Generally, both terms, constants and literals are used interchangeably. For eg, “const int = 5;“, is a constant expression and the value 5 is referred to as constant integer literal.
- Access Modifiers in C++: Access modifiers are used to implement an important feature of Object-Oriented Programming known as Data Hiding. Access modifiers or Access Specifiers in a class are used to set the accessibility of the class members. That is, it sets some restrictions on the class members not to get directly accessed by the outside functions.
- Storage Classes in C++: Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility, and life-time which help us to trace the existence of a particular variable during the runtime of a program.
- Operators in C++: Operators are the foundation of any programming language. Thus the functionality of C/C++ programming language is incomplete without the use of operators. We can define operators as symbols that help us to perform specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands.
- Loops in C++: Loops in programming comes into use when we need to repeatedly execute a block of statements. For example: Suppose we want to print “Hello World” 10 times. This can be done in two ways, Iterative method and by using Loops.
- Decision Making in C++:There comes situations in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations arise in programming also where we need to make some decisions and based on these decisions we will execute the next block of code. Decision-making statements in programming languages decide the direction of flow of program execution.
- Forward declarations in C++: It refers to the beforehand declaration of the syntax or signature of an identifier, variable, function, class, etc. prior to its usage (done later in the program). In C++, Forward declarations are usually used for Classes. In this, the class is pre-defined before its use so that it can be called and used by other classes that are defined before this.
- Errors in C++: Error is an illegal operation performed by the user which results in abnormal working of the program. Programming errors often remain undetected until the program is compiled or executed. Some of the errors inhibit the program from getting compiled or executed. Thus errors should be removed before compiling and executing.
بناء الجملة والبرنامج الأول في C ++: يمكن تبسيط تعلم برمجة C ++ في كتابة برنامجك في محرر نصوص وحفظه بامتداد صحيح (.CPP ، .C ، .CP) وتجميع برنامجك باستخدام مترجم أو IDE عبر الإنترنت. برنامج "Hello World" هو الخطوة الأولى نحو تعلم أي لغة برمجة وأيضًا أحد أبسط البرامج التي ستتعلمها.
I / O الأساسي في C ++: يأتي C ++ مع مكتبات توفر لنا العديد من الطرق لأداء الإدخال والإخراج. في لغة C ++ ، يتم تنفيذ المدخلات والمخرجات في شكل سلسلة من البايتات أو المعروفة باسم التدفقات. يتم استخدام الكلمتين الأساسيتين cin و cout كثيرًا لأخذ المدخلات ومخرجات الطباعة على التوالي. هاتان الطريقتان هما أبسط الطرق لأخذ المدخلات والمخرجات في C ++.
التعليقات في C ++: يعد البرنامج الموثق جيدًا ممارسة جيدة كمبرمج. فهو يجعل البرنامج أكثر قابلية للقراءة ويصبح اكتشاف الأخطاء أسهل. جزء مهم من التوثيق الجيد هو التعليقات. في برمجة الكمبيوتر ، التعليق هو شرح أو شرح مقروء من قبل المبرمج في الكود المصدري لبرنامج الكمبيوتر. هذه هي العبارات التي لم يتم تنفيذها من قبل المترجم والمترجم.
أنواع ومعدلات البيانات في C ++: تستخدم جميع المتغيرات نوع البيانات أثناء الإعلان لتقييد نوع البيانات المراد تخزينها. لذلك ، يمكننا القول أن أنواع البيانات تُستخدم لإخبار المتغيرات بنوع البيانات التي يمكن تخزينها. عندما يتم تعريف متغير في C ++ ، يخصص المترجم بعض الذاكرة لذلك المتغير بناءً على نوع البيانات الذي تم الإعلان عنه. يتطلب كل نوع بيانات مقدارًا مختلفًا من الذاكرة.
متغير غير مهيأ في C ++: "أحد الأشياء التي أبقت C ++ قابلة للتطبيق هي قاعدة صفر النفقات العامة: ما لا تستخدمه ، لا تدفع مقابله." -ستروستروب. يعتبر الحمل الزائد لتهيئة متغير مكدس مكلفًا لأنه يعيق سرعة التنفيذ ، وبالتالي يمكن أن تحتوي هذه المتغيرات على قيم غير محددة. يعتبر من أفضل الممارسات تهيئة متغير نوع بيانات بدائي قبل استخدامه في الكود.
سلوك غير محدد في C ++: إذا بدأ المستخدم التعلم في بيئة C / C ++ ولم يكن واضحًا مع مفهوم السلوك غير المحدد ، فقد يؤدي ذلك إلى حدوث الكثير من المشكلات في المستقبل ، مثل أثناء تصحيح أخطاء رمز شخص آخر ، قد يكون من الصعب بالفعل تتبع الجذر إلى خطأ غير محدد.
المتغيرات والأنواع في C ++: المتغير هو الاسم الذي يطلق على موقع الذاكرة. إنها وحدة التخزين الأساسية في البرنامج. يمكن تغيير القيمة المخزنة في متغير أثناء تنفيذ البرنامج. المتغير هو فقط اسم يُعطى لموقع الذاكرة ، كل العمليات التي تتم على التأثيرات المتغيرة لموقع الذاكرة. في C ++ ، يجب التصريح عن جميع المتغيرات قبل الاستخدام.
النطاق المتغير في C ++: بشكل عام ، يُعرّف النطاق على أنه المدى الذي يمكن العمل به مع شيء ما. في البرمجة أيضًا ، يتم تعريف نطاق المتغير على أنه مدى كود البرنامج الذي يمكن من خلاله الوصول إلى المتغير أو الإعلان عنه أو العمل معه. هناك نوعان رئيسيان من النطاقات المتغيرة ، المتغيرات المحلية والعالمية.
الثوابت والحرفية في C ++: كما يوحي الاسم ، يتم إعطاء ثوابت الاسم لمثل هذه المتغيرات أو القيم في لغة البرمجة C ++ والتي لا يمكن تعديلها بمجرد تعريفها. إنها قيم ثابتة في البرنامج. يمكن أن يكون هناك أي أنواع من الثوابت مثل الأعداد الصحيحة ، والعائمة ، والثمانية ، والسداسية العشرية ، وثوابت المحارف ، وما إلى ذلك ، ولكل ثابت بعض النطاق. الأعداد الصحيحة التي تكون أكبر من أن تتناسب مع عدد صحيح سيتم أخذها طويلة. توجد الآن نطاقات مختلفة تختلف من البتات غير الموقعة إلى البتات الموقعة. تحت البتة الموقّعة ، يختلف نطاق int من -128 إلى +127 وتحت البت غير الموقعة ، يختلف int من 0 إلى 255. تعد القيم الحرفية نوعًا من الثوابت ويتم استخدام كلا المصطلحين بالتبادل في C ++.
أنواع الحروف في C ++: سنحلل في هذه المقالة الأنواع المختلفة من المعطيات الحرفية التي توفرها C ++. يشار إلى القيم المخصصة لكل متغير ثابت بالقيم الحرفية. بشكل عام ، يتم استخدام كلا المصطلحين والثوابت والحرفية بالتبادل. على سبيل المثال ، "const int = 5 ؛" ، هو تعبير ثابت ويشار إلى القيمة 5 على أنها حرفية عدد صحيح ثابت.
معدِّلات الوصول في C ++: تُستخدم معدِّلات الوصول لتنفيذ ميزة مهمة في البرمجة الموجهة للكائنات تُعرف باسم إخفاء البيانات. تُستخدم مُعدِّلات الوصول أو محددات الوصول في فئة ما لتعيين إمكانية الوصول لأعضاء الفئة. أي أنه يضع بعض القيود على أعضاء الفصل لعدم الوصول مباشرة إلى الوظائف الخارجية.
فئات التخزين في C ++: تُستخدم فئات التخزين لوصف ميزات المتغير / الوظيفة. تتضمن هذه الميزات بشكل أساسي النطاق والرؤية ووقت الحياة والتي تساعدنا على تتبع وجود متغير معين أثناء وقت تشغيل البرنامج.
العوامل في C ++: العوامل هي أساس أي لغة برمجة. وبالتالي فإن وظائف لغة البرمجة C / C ++ غير مكتملة بدون استخدام عوامل التشغيل. يمكننا تعريف العوامل على أنها رموز تساعدنا في إجراء حسابات رياضية ومنطقية محددة على المعاملات. بعبارة أخرى ، يمكننا القول أن المشغل يشغل المعاملات.
الحلقات في C ++: يتم استخدام الحلقات في البرمجة عندما نحتاج إلى تنفيذ مجموعة من العبارات بشكل متكرر. على سبيل المثال: لنفترض أننا نريد طباعة "Hello World" 10 مرات. يمكن القيام بذلك بطريقتين ، الطريقة التكرارية وباستخدام الحلقات Loops.
اتخاذ القرار في C ++: هناك مواقف في الحياة الواقعية عندما نحتاج إلى اتخاذ بعض القرارات وبناءً على هذه القرارات ، نقرر ما يجب أن نفعله بعد ذلك. تظهر مواقف مماثلة في البرمجة أيضًا حيث نحتاج إلى اتخاذ بعض القرارات وبناءً على هذه القرارات سننفذ الكتلة التالية من التعليمات البرمجية. تحدد بيانات صنع القرار في لغات البرمجة اتجاه تدفق تنفيذ البرنامج.
التصريحات إلى الأمام في C ++: يشير إلى الإعلان المسبق عن بناء الجملة أو توقيع المعرف ، المتغير ، الوظيفة ، الفئة ، إلخ قبل استخدامه (يتم ذلك لاحقًا في البرنامج). في لغة C ++ ، تُستخدم الإعلانات إلى الأمام عادةً للفئات. في هذا ، يتم تعريف الفئة مسبقًا قبل استخدامها بحيث يمكن استدعاؤها واستخدامها من قبل الفئات الأخرى التي تم تحديدها قبل ذلك.
أخطاء في C ++: الخطأ هو عملية غير قانونية يقوم بها المستخدم وينتج عنها عمل غير طبيعي للبرنامج. غالبًا ما تظل أخطاء البرمجة غير مكتشفة حتى يتم تجميع البرنامج أو تنفيذه. تمنع بعض الأخطاء البرنامج من التجميع أو التنفيذ. وبالتالي يجب إزالة الأخطاء من قبل
0 comments:
Post a Comment