C++ da belgilar ishlatilishi
Published: 2023-02-02 06:30:23

C++ da belgilar doim " " ichida yoziladi. Belgilarni to'g'ri yozishda doimo yodda saqlashimiz lozim bo'lgan bir qancha qoidalar mavjud.

## \ (backslash) 
Consoleda `\(backslash)` chiqarmoqchi bo'lsak, uni `\\` shaklida yozishimiz kerak. 
1ta `\(backslash)` chiqarmoqchi bo'lsak, `\\` yozamiz.
2ta `\(backslash)` chiqarmoqchi bo'lsak, `\\\\` ko'rinishida yozishimiz lozim. Aks holda, kodimiz xato yozilgan hisoblanadi va console da ko'rinmaydi.

```cpp
#include <iostream>
using namespace std;

int main(){

  cout << "\\" << endl;    // consoleda 1ta \(backlash) chiqadi
  cout << "\\\\" << endl;  // consoleda 2ta \(backslash) chiqadi
  cout << "\\\\\\";        // consoleda 3ta \(backslash) chiqadi
  
  return 0;
}

```

Consoleda ko'rinishi:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z3qlvbfx6rbbhqx0uq4o.jpg)

## " (qo'shtirnoq)
 Consoleda `"(qo'shtirnoq)` chiqarmoqchi bo'sak, `\"` shaklida yozishimiz kerak. Natijada consoleda `"` belgisi chiqadi.

```cpp
#include <iostream>
using namespace std;

int main(){

  cout << "Bugungi darsda Consoleda \" belgisini chiqarishni o'rgandik" << endl << endl;
  
  cout << "Consoleda \" ni chiqarish uchun doimo \\ dan foydalanamiz"; 

  return 0;
}
```

## Matnni kommentariyaga olish
Kod yozayotganimizda ayni kodni nima sababdan yozyotganimizni keyinchalik o'zimiz uchun eslab olishimizga qulay bo'lishi uchun ularni kommentariya ichida tushuntirib ketsak ham bo'ladi. Yozgan matnimiz oldiga 2ta / ya'ni `//` yozsak, matn kommentariyaga olinadi. Bu degani biz yozgan matn kodimiz yonida ko'rinib turgani bilan consoleda ko'rinmaydi. U faqat o'zimizga qaysi kodni nega ishlatganimizni bilib turish uchun xizmat qiladi xolos. 

```cpp
#include <iostream>
using namespace std;

int main(){

  cout << "\\" << endl;    // consoleda 1ta \(backlash) chiqadi
  cout << "\\\\" << endl;  // consoleda 2ta \(backslash) chiqadi
  cout << "\\\\\\";        // consoleda 3ta \(backslash) chiqadi
  
  return 0;
}

```

## `\` belgisining muhimligi 
Quyidagi kodda `\(backslash)` qoidaga binoan yozilmaganligi sababli consoleda ko'rinmaydi va consoleda / ^ belgilari chiqadi xolos.

```cpp
#include <iostream>
using namespace std;

int main(){

  cout << "\ \ \ \ / ^ ";

  return 0;
}
```


Consoleda ko'rinishi:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jfhzl5xdoewbr832wqv.jpg)

## Masalalar
1-topshiriq. Quyida ko'rsatilgandek mushukcha chop eting.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk7w78jbgrnl90e7a5w5.jpg)

Yechim:


```cpp
#include <iostream>
using namespace std;

int main(){

  cout << "\\    /\\" << endl;
  cout << " )  ( ')" << endl;
  cout << "(  /  )" << endl;
  cout << " \\(__)|";

  return 0;
}
 
```

Consoleda ko'rinishi:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7bnictmk24rkseh3nb0.jpg)

2-topshiriq. Namunada berilgan yakkashoxni chop eting.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1p3ihovehxhgjhet5ek.jpg)

Yechim:

```cpp
#include <iostream>
using namespace std;

int main(){

  cout << "      _/\\__" << endl;
  cout << "---==/    \\\\" << endl;
  cout << "     |.    \\|\\" << endl;
  cout << "     |  )   \\\\\\" << endl;
  cout << "     \\_/ |  //|\\\\" << endl;
  cout << "        /   \\\\\\/\\\\";

  return 0;
}
```

Consoleda ko'rinishi:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ntcom2xk8dy8grt4p61.jpg)

Topshiriqlar https://oj.ilmhub.uz/ saytidan olindi.