Var
N,A:integer;
Begin
Write('N = ');Read(N);
A:=0;
While N>0 do
if (N mod 10) > A then A:= N mod 10;
N:=N div 10;
End;
Write(A)
End.
N,A,B:integer;
C:boolean;
A:=-1;
B:=-2;
C:=false;
if A=B then C:=true;
if N>0 then
A:=N mod 10;
B:=N mod 10;
if C then Write('Есть')
else Write('Нет')
Подробнее - на -
/* memsegments.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct mem
{
char text[100];
int *p;
} mem;
int cmp_by_address(const void *, const void *);
void print_struct_array(mem *, size_t);
int init_global_var = 10; /* Initialized global variable */
int global_var; /* Uninitialized global variable */
static int init_static_var = 20; /* Initialized static variable in global scope */
static int static_var; /* Uninitialized static variable in global scope */
int main(int argc, char **argv, char **envp)
static int init_static_local_var = 30; /* Initialized static local variable */
static int static_local_var; /* Uninitialized static local variable */
int init_local_var = 40; /* Initialized local variable */
int local_var; /* Uninitialized local variable */
int *dynamic_var = (int*)malloc(sizeof(int)); /* Dynamic variable */
mem structs[] =
{"Global variable (initialized)", &init_global_var},
{"Global variable (uninitialized)", &global_var},
{"Static variable (in global scope, initialized)", &init_static_var},
{"Static variable (in global scope, uninitialized)", &static_var},
{"Static variable (in local scope, initialized)", &init_static_local_var},
{"Static variable (in local scope, uninitialized)", &static_local_var },
{"Function (code)", (int*)&main },
{"Environment variable", (int*)&envp[0] },
{"Local variable (initialized)", &init_local_var },
{"Local variable (uninitialized)", &local_var },
{"Dynamic variable", dynamic_var },
};
size_t len = sizeof(structs) / sizeof(mem);
qsort(structs, len, sizeof(mem), cmp_by_address);
print_struct_array(structs, len);
free(dynamic_var);
return 0;
}
int cmp_by_address(const void *a, const void *b)
mem *ma = (mem *)a;
mem *mb = (mem *)b;
if ((unsigned)ma->p > (unsigned)mb->p)
return -1;
else if ((unsigned)ma->p < (unsigned)mb->p)
return 1;
else
/* Example struct array printing function */
void print_struct_array(mem *array, size_t len)
size_t i;
for(i=0; i<len; i++)
printf("%-50s:\t%p\n", array[i].text, array[i].p);
В результате получим:
Environment variable : 0xbff52ee0
Local variable (uninitialized) : 0xbff529ac
Local variable (initialized) : 0xbff529a8
Dynamic variable : 0x871c008
Global variable (uninitialized) : 0x804a044
Static variable (in local scope, uninitialized) : 0x804a040
Static variable (in global scope, uninitialized) : 0x804a03c
Static variable (in local scope, initialized) : 0x804a034
Static variable (in global scope, initialized) : 0x804a030
Global variable (initialized) : 0x804a02c
Function (code) : 0x80484ad
Утилита size показывает размер разделов и общий размер для объектных файлов или архивов. Так, для memsegments.o получим:
$ size memsegments.o
text data bss dec hex filename
745 12 8 765 2fd memsegments.o
Объяснение:
Var
N,A:integer;
Begin
Write('N = ');Read(N);
A:=0;
While N>0 do
Begin
if (N mod 10) > A then A:= N mod 10;
N:=N div 10;
End;
Write(A)
End.
Var
N,A,B:integer;
C:boolean;
Begin
Write('N = ');Read(N);
A:=-1;
B:=-2;
C:=false;
While N>0 do
Begin
if A=B then C:=true;
if N>0 then
Begin
A:=N mod 10;
N:=N div 10;
End;
if A=B then C:=true;
if N>0 then
Begin
B:=N mod 10;
N:=N div 10;
End;
End;
if A=B then C:=true;
if C then Write('Есть')
else Write('Нет')
End.
Подробнее - на -
/* memsegments.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct mem
{
char text[100];
int *p;
} mem;
int cmp_by_address(const void *, const void *);
void print_struct_array(mem *, size_t);
int init_global_var = 10; /* Initialized global variable */
int global_var; /* Uninitialized global variable */
static int init_static_var = 20; /* Initialized static variable in global scope */
static int static_var; /* Uninitialized static variable in global scope */
int main(int argc, char **argv, char **envp)
{
static int init_static_local_var = 30; /* Initialized static local variable */
static int static_local_var; /* Uninitialized static local variable */
int init_local_var = 40; /* Initialized local variable */
int local_var; /* Uninitialized local variable */
int *dynamic_var = (int*)malloc(sizeof(int)); /* Dynamic variable */
mem structs[] =
{
{"Global variable (initialized)", &init_global_var},
{"Global variable (uninitialized)", &global_var},
{"Static variable (in global scope, initialized)", &init_static_var},
{"Static variable (in global scope, uninitialized)", &static_var},
{"Static variable (in local scope, initialized)", &init_static_local_var},
{"Static variable (in local scope, uninitialized)", &static_local_var },
{"Function (code)", (int*)&main },
{"Environment variable", (int*)&envp[0] },
{"Local variable (initialized)", &init_local_var },
{"Local variable (uninitialized)", &local_var },
{"Dynamic variable", dynamic_var },
};
size_t len = sizeof(structs) / sizeof(mem);
qsort(structs, len, sizeof(mem), cmp_by_address);
print_struct_array(structs, len);
free(dynamic_var);
return 0;
}
int cmp_by_address(const void *a, const void *b)
{
mem *ma = (mem *)a;
mem *mb = (mem *)b;
if ((unsigned)ma->p > (unsigned)mb->p)
return -1;
else if ((unsigned)ma->p < (unsigned)mb->p)
return 1;
else
return 0;
}
/* Example struct array printing function */
void print_struct_array(mem *array, size_t len)
{
size_t i;
for(i=0; i<len; i++)
printf("%-50s:\t%p\n", array[i].text, array[i].p);
}
В результате получим:
Environment variable : 0xbff52ee0
Local variable (uninitialized) : 0xbff529ac
Local variable (initialized) : 0xbff529a8
Dynamic variable : 0x871c008
Global variable (uninitialized) : 0x804a044
Static variable (in local scope, uninitialized) : 0x804a040
Static variable (in global scope, uninitialized) : 0x804a03c
Static variable (in local scope, initialized) : 0x804a034
Static variable (in global scope, initialized) : 0x804a030
Global variable (initialized) : 0x804a02c
Function (code) : 0x80484ad
Утилита size показывает размер разделов и общий размер для объектных файлов или архивов. Так, для memsegments.o получим:
$ size memsegments.o
text data bss dec hex filename
745 12 8 765 2fd memsegments.o
Объяснение: