Showing posts with label datatypes. Show all posts
Showing posts with label datatypes. Show all posts

Monday, April 01, 2024

Master the Fundamentals of C# 12 Programming, How to use Variables, Data Types, and Constants in Your Projects?

In the previous lesson, we created our first C# 12 program. We learned how to print text to the Terminal panel and explored the three types of comments used in the C# programming language. Additionally, we discovered how to set attributes in the *.csproj file, which affects the entire project. We also delved into creating regions, which allow us to organize code into blocks and navigate through it easily, regardless of the number of lines of code.

Furthermore, despite the convenience of C# 12’s top-level statements, we can still create programs with the traditional Main method that you might recognize from older versions of the C# programming language. However, everything we’ve learned so far would only suffice for printing text on consoles. Programming encompasses much more than that! Let’s first focus on what programming is and what it involves.

A boy is learning C# 12 programming at home

A boy is learning C# 12 programming at home to make a game

Programming is the process of creating computer programs, where programmers use a specific language and tools to communicate with the computer. Programming is the art of writing code that enables computers to perform specific tasks and Programmers use various languages (such as C#, Python, Java, etc.) to write instructions for the computer. In any case, programming requires creativity and problem-solving skills. It goes beyond mere code writing. It involves creating solutions, thinking about problems, and communicating with computers to achieve desired functionality.

Programmers often need to devise innovative ways to tackle challenges. But how do computers actually function? Programming involves giving instructions to the computer in the form of one or more grouped lines of code, known as statements. These statements are grouped into methods, and methods into classes, to avoid code repetition in a project and enable calling previously written and tested code from other parts of the project. 

The code you write must have a purpose and be written with a significant reason. It should also be correct and optimized. Your computer will always execute exactly what you've instructed, regardless of whether it's logical. Logic and proper code writing are up to you. Learning programming usually begins with console applications. Although console applications aren’t used for creating market-ready 
programs due to their purely textual user interface, they are excellent for testing methods and classes.

Understanding Declarations, Variables, Data Types, and the Role of Constants

Sunday, May 28, 2023

Preuzmi kontrolu nad svojim C++ kodom, nauči promenjive, tipove podataka i konstante

Promenjiva – variable je lokacija u memoriji računara na kojoj čuvate određenu vrednost i iz koje možete da menjate ili preuzmete vrednost. Jednostavno memoriju računara zamislite kao niz memorijski lokacija. Memorijske lokacije su numerisane i njih nazivamo memorijske adrese. Jedna promenjiva rezerviše jednu ili više memorijski lokacija u kojoj će se čuvati neka vrednost. Sve vaše promenjive se kreiraju u RAM - Random Access Memorymemoriji. Kad vi promenjivoj zadate ime promenjive, vi ne morate znati stvarnu memorijsku adresu promenjive. Vi promenjivoj pristupate preko njenog imena i njena memorijska adresa ostaje ista tokom trajanja promenjive. Ali ukoliko bi ste pokrenuli vaš program i ugasili ga, zatim ga ponovo pokrenuli; vaša promenjiva bi imala drugu memorijsku adresu. Promenjive koristimo da uzmemo podatke od korisnika ili sami možemo definisati njihove vrednosti u kodu. Da bi ste napravili i koristili neku promenjivu vi je prvo morate deklarisati. Iako računar tretira sve promenjive i čuva ih kao brojeve, programeri promenjive dele prema potrebama u 3 osnovna formata.



 ( C++ Datatypes )

Promenjive delimo pre svega na formate, celi broj – Integerbroj sa pokretnim zarezom – Floating Point i tekstualni string – Text StringPored osnovnih formata promenjivih; postoje i mnoštvo tipova promenjivih koji su u principu izvedeni od već navedenih formata. Svaki format promenjivih ima više tipova promenjivi. Vi čak možete definisati i praviti svoje vlastite tipove promenjivih, iako za tim nećete imati potrebe. Najvažnije je da shvatite da svaka vrednost ima prvo svoj format, zatim i svoj tip promenjive. Na primer, decimalne brojeve ćete stavljati u promenjivu formata Floating Point, u tip podataka Float ili Double dok ćete tekst stavljati u format promenjivih String. Međutim vaš računar će prevesti svaku vašu promenjivu i čuvati kao binarni broj bez obzira koji ćete format i tip podataka koristiti. Osnovni tipovi u C++ programskom jeziku su:

char                                                     1 bajt            256 znakova

unsigned short int                              2 bajta          od 0 do 65 535

short int                                              2 bajta          od – 32 768 do 32 767

unsigned int (16 bitova)                    2 bajta          od 0 do 65 535

unsigned int (32 bitova)                    4 bajta          od 0 do 4 294 967 295

int (16 bitova)                                     2 bajta         od – 32 768 do 32 767

int (32 bita)                                         4 bajta         od – 2 147 483 648 do 2 147 647

unsigned long int                               4 bajta          od 0 do 4 294 967 295

long int                                               4 bajta          od – 2 147 483 648 do 2 147 483 647

float                                                    4 bajta          od 1,2e-38 do 3,4e38

double                                                8 bajtova      od  2,2e-308 do 1,8e308

Imajte u vidu da ove vrednosti na vašem računaru mogu da variraju u zavisnosti od vašeg računara i kompajlera. Da bi ste napravili i koristili promenjivu prvo je potrebno da je deklarišete.

Kako da deklarišem neku promenjivu?