char a char p new char p a
- Slides: 42
Операция разадресации char a; char * p = new char; *p = 'Ю'; a = *p; #include <stdio. h> int main(){ unsigned long int A = 0 Xсс77 ffaa; unsigned int* pint = (unsigned int *) &A; unsigned char* pchar = (unsigned char *) &A; printf(" | %x |", *pint, *pchar); } | ffaa | | cc 77 | ffaa | ©Павловская Т. А. (СПб. ГУ ИТМО)
Массивы #include <iostream. h> int main(){ const int n = 10; int marks[n] = {3, 4, 5, 4, 4}; int i, sum; for ( i = 0, sum = 0; i<n; i++) sum += marks[i]; cout << "Сумма элементов: " << sum; } int a[100], b[100]; int *pa = a; // или int *p = &a[0]; int *pb = b; for(int i = 0; i<100; i++)*pb++ = *pa++; // или pb[i] = pa[i]; ©Павловская Т. А. (СПб. ГУ ИТМО)
Пример - сортировка выбором #include <iostream. h> int main(){ const int n = 20; int b[n]; for (i = 0; i<n; i++) cin >> b[i]; int i; for (i = 0; i<n-1; i++){ int imin = i; for (int j = i + 1; j<n; j++) if (b[j] < b[imin]) imin = j; int a = b[i]; b[i] = b[imin]; b[imin] = a; } for (i = 0; i<n; i++)cout << b[i] << ' '; return 0; } ©Павловская Т. А. (СПб. ГУ ИТМО)
Пример 2 - строки char src[10], dest[10]; for (int i = 0; i <= strlen(src); i++) dest[i] = src[i]; char *src = new char [10]; char *dest = new char [10], *d = dest; cin << src; while ( *src != 0) *d++ = *src++; *d = 0; while ( *d++ = *src++); ©Павловская Т. А. (СПб. ГУ ИТМО)
Типы данных, определяемые пользователем enum Переименование типов (typedef) struct typedef тип новое_имя [ размерность ]; union typedef unsigned int UINT; typedef char Msg[100]; typedef struct{ char fio[30]; int date, code; float salary; } Worker; UINT i, j; Msg str[10]; Worker stuff[100]; ©Павловская Т. А. (СПб. ГУ ИТМО)
Перечисления ( enum ) enum [ имя_типа ] { список_констант }; enum Err { ERR_READ, ERR_WRITE, ERR_CONVERT}; Err error; switch (error){ case ERR_READ: /* оп */ break; case ERR_WRITE: /* оп */ break; case ERR_CONVERT: /* оп */ break; } enum {two = 2, three, four, ten = 10, eleven, fifty = 50}; ©Павловская Т. А. (СПб. ГУ ИТМО)
Инициализация структур struct{ char fio[30]; int date, code; float salary; }worker = {"Страусенко", 31, 215, 3400. 55}; struct complex { float real, im; } compl [2][3]={ {{1, 1}, {1, 1}}, {{2, 2}, {2, 2}} }; ©Павловская Т. А. (СПб. ГУ ИТМО)
Доступ к полям структуры Worker worker, staff[100], *ps; worker. fio = "Страусенко"; staff[8]. code = 215; ps->salary = 0. 12; struct A struct B x[0]. a. a x[1]. х = ©Павловская Т. А. (СПб. ГУ ИТМО) {int a; double x; }; {A a; double x; } x[2]; = 1; 0. 1;
Битовые поля struct Options { bool center. X: 1; bool center. Y: 1; unsigned int shadow: 2; unsigned int palette: 4; }; ©Павловская Т. А. (СПб. ГУ ИТМО)
Объединения ( union ) #include <iostream. h> int main(){ enum paytype {CARD, CHECK}; paytype ptype; union payment{ char card[25]; long check; } info; /* присваивание значений info и ptype */ switch (ptype){ case CARD: cout << "Оплата по карте: " << info. card; break; case CHECK: cout << "Оплата чеком: " << info. check; break; }} ©Павловская Т. А. (СПб. ГУ ИТМО)
struct Options { bool center. X: 1; bool center. Y: 1; unsigned int shadow: 2; unsigned int palette: 4; }; union { unsigned char ch; Options bit; }option = {0 x. C 4}; cout << option. bit. palette; option. ch &= 0 x. F 0; ©Павловская Т. А. (СПб. ГУ ИТМО)
- Auto break case char
- Const int size=18; string *tb12 = new string[size];
- Marketing management
- Both new hampshire and new york desire more territory
- Marquee cinema new hartford ny
- Njbta
- Punctuating split speech
- New classical and new keynesian macroeconomics
- Strengths of articles of confederation
- New classical macroeconomics
- New york, new jersey, pennsylvania, and delaware
- Comparing progressive presidents roosevelt taft and wilson
- New-old approach to creating new ventures
- Chapter 16 toward a new heaven and a new earth
- Fresh oil new wine
- Seou;
- Char argv
- Void fun(int *ptr)
- Int score
- 쉽게 풀어쓴 c언어 express 4장
- Unsigned char ascii table
- Int main(int argc, char** argv)
- Integer real string boolean
- L char
- 1 char kaç byte
- Char str
- Sideshow bob personality type
- C언어 입출력 함수
- V int
- Char
- Ejemplo de char
- Struct student char *name
- Ascii to string matlab
- Char computer science
- Character data type
- Char name
- Void encode_char(const char character, bool bits[8])
- Stdio.h
- Char str
- Short 형
- Constant int arduino
- Char
- Char and string