Skip to content
Snippets Groups Projects
Commit f9aeee47 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele 16.10.2023, Praktikumsunterlagen Versuch 1

parent 665f9c39
No related branches found
No related tags found
No related merge requests found
Showing
with 308 additions and 0 deletions
#include <stdio.h>
int main (void)
{
char *a[] = { "Dies", "ist", "ein", "Test", NULL };
char **p = a;
while (*p)
printf ("%s\n", *p++);
return 0;
}
#include <stdio.h>
int main (void)
{
char *a[] = { "Dies", "ist", "ein", "Test", NULL };
char **p = &a;
while (*p)
printf ("%s\n", *p++);
return 0;
}
program ArraysAndPointers;
var
a: array [0..4] of CString = ( @'Dies', @'ist', @'ein', @'Test', nil );
p: ^CString = @a[0];
begin
while p^ <> nil do
begin
WriteLn (p^);
Inc (p)
end
end.
program ArraysAndPointers;
var
a: array [0..4] of CString = ( @'Dies', @'ist', @'ein', @'Test', nil );
p: ^CString = @a[0];
begin
while p^ <> nil do
begin
WriteLn (p^);
Inc (p)
end
end.
cassini/home/peter/bo/2023ws/es/20231016> gpc -Wall -O --cstrings-as-strings --pointer-arithmetic arrays-pointers-03.pas
cassini/home/peter/bo/2023ws/es/20231016> ./a.out Dies
ist
ein
Test
cassini/home/peter/bo/2023ws/es/20231016>
program ArraysAndPointers;
var
a: array [0..4] of CString = ( @'Dies', @'ist', @'ein', @'Test', nil );
p: ^CString = @a;
begin
while p^ <> nil do
begin
WriteLn (p^);
Inc (p)
end
end.
program ArraysAndPointers;
type
PCString = ^CString;
var
a: array [0..4] of CString = ( @'Dies', @'ist', @'ein', @'Test', nil );
p: ^CString = PCString (@a);
begin
while p^ <> nil do
begin
WriteLn (p^);
Inc (p)
end
end.
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", NULL };
char *p = a[0];
while (*p)
printf ("%s\n", (p += 5, p - 5));
return 0;
}
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", NULL };
char *p = a[0];
while (*p)
{
printf ("%s\n", p);
p += 5;
}
return 0;
}
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", { 0, 0, 0, 0, 0 } };
char *p = a[0];
while (*p)
{
printf ("%s\n", p);
p += 5;
}
return 0;
}
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", "\x00\x00\x00\x00" };
char *p = a[0];
while (*p)
{
printf ("%s\n", p);
p += 5;
}
return 0;
}
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", "" };
char *p = a[0];
while (*p)
{
printf ("%s\n", p);
p += 5;
}
return 0;
}
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", { 0 } };
char *p = a[0];
while (*p)
{
printf ("%s\n", p);
p += 5;
}
return 0;
}
#include <stdio.h>
int main (void)
{
char a[][5] = { "Dies", "ist", "ein", "Test", { 0 } };
int i = 0;
while (a[i][0])
{
printf ("%s\n", a[i]);
i++;
}
return 0;
}
#include <stdio.h>
int main (void)
{
typedef char string5[5];
string5 a[] = { "Dies", "ist", "ein", "Test", { 0 } };
string5 *p = a;
while (**p)
printf ("%s\n", *p++);
return 0;
}
#include <stdio.h>
int main (void)
{
typedef char string5[5];
string5 *p = { "Dies", "ist", "ein", "Test", { 0 } };
while (**p)
printf ("%s\n", *p++);
return 0;
}
.file "arrays-pointers-14.c"
.text
.section .rodata
.LC0:
.string "Dies"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
leaq .LC0(%rip), %rax
movq %rax, -8(%rbp)
jmp .L2
.L3:
movq -8(%rbp), %rax
leaq 5(%rax), %rdx
movq %rdx, -8(%rbp)
movq %rax, %rdi
call puts@PLT
.L2:
movq -8(%rbp), %rax
movzbl (%rax), %eax
testb %al, %al
jne .L3
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
typedef char string5[5];
volatile string5 *p = { "Dies", "ist", "ein", "Test", { 0 } };
while (**p)
printf ("%s\n", *p++);
return 0;
}
#include <stdio.h>
int main (void)
{
typedef char string5[5];
string5 *p = { (volatile char *) "Dies",
(volatile char *) "ist",
(volatile char *) "ein",
(volatile char *) "Test",
(volatile char *) { 0 } };
while (**p)
printf ("%s\n", *p++);
return 0;
}
.file "arrays-pointers-16.c"
.text
.section .rodata
.LC0:
.string "Dies"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
leaq .LC0(%rip), %rax
movq %rax, -8(%rbp)
jmp .L2
.L3:
movq -8(%rbp), %rax
leaq 5(%rax), %rdx
movq %rdx, -8(%rbp)
movq %rax, %rdi
call puts@PLT
.L2:
movq -8(%rbp), %rax
movzbl (%rax), %eax
testb %al, %al
jne .L3
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Debian 12.2.0-14) 12.2.0"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
typedef char string5[5];
string5 *p = { (volatile (char *)) "Dies",
(volatile (char *)) "ist",
(volatile (char *)) "ein",
(volatile (char *)) "Test",
(volatile (char *)) { 0 } };
while (**p)
printf ("%s\n", *p++);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment