C&Bash Flashcards

1
Q

Declare an Array of characters initialized with ‘Hyper!’

A

char str[ ] = “Hyper!”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Declare an Array of shorts of length 10 with the first number initialized as 0.
Given: #Define SHORT_ARRAY_LEN 10

A

(Der rest der werte auch mit 0 belegt, da keine vollst. initialisierung vorgenommen)

short array_short[SHORT_ARRAY_LEN] = {0};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Declare a Pointer to a char and a Pointer to a long.

A

char *p_str;

long *p_long;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

GIVEN:
char array[5]={‘a’,’b’,’c’,’d’,0};
char *ptr;
What does ptr = array; do?

A

since ptr is a char pointer what we have here is:
char *ptr = array char *ptr =&array[0];
ptr = array ptr = &array[0];
So it points on the first element of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Given: char p[5]; char q[ ]=”Hello”;

What is: sizeof(p), sizeof(q), strlen(p) and strlen(q)

A

(sizeofp = 5) and p looks like: [ ] [ ] [ ] [ ] [0]
(sizeofq = 6) because the 0 terminator is implicitly added after every string.
but (strlen(q)=5) since only H E L L O are considered als characters
and q looks like: [H][E][L][L][O] ![0]!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does %2d, %p and %c stand for?

A
######## %2d #############
int n = 0;
scanf ("%2d", &n);
printf ("->" %d" , n);
// 12 -> 12 and 23432 -->23
#########  %p #############
%p is for printing a pointers adress
#########  %c #############
%c prints the ASCII representation of the character whereas %d prints its decimal value.
%ld represents  longdecimals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe

1) int *B[N];
2) int (F )( );

A

1) int *B[N];
Ein Array von Pointern auf int. Das Array hat länge N.
2) int (F )( );
Ein Pointer auf eine Funktion mit beliebig vielen Argumenten, Diese Funktion liefert einen Pointer auf int zurück.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does feof?

A

check if end of file, ob ein dateizeiger am ende der Datei steht

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Gib einen Befehl in Bash an, mit der in einer über standard in gelesenen Zeichenkette die erste 4 durch eine 5 ersetzt wird

A

$ echo “BuS 2014 die 2te 4” I sed “s/4/5/1”

sed ‘substitute/4/with 5/ only the first 4’
sed ‘s/4/5/’ auch möglich dann wird standardmässig das erste auftreten der 4 ersetzt.
sed ‘s/4/5/(2)’ beim (zweiten auftreten) von 4, 4 mit 5 ersetzen.
Um jedes auftreten zu ersetzen als letztes parameter g(global)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Was tut :

find . -name ‘d*’ -exec cat {} \; I cut -d ‘ ‘ -f 1

A
Finde rekursiv (.) alle daten deren name (-name) mit kleinem d anfangen('d*') und führe (-exec) einen Befehl auf den gefundenen Dateien aus:
cat hängt die Inhalte der gefundenen Dateien hintereinander an und gibt diese in der Standartausgabe aus.
{ } ist der Platzhalter für den Namen der jeweiligen gefundenen Datei, der bei AUsführung eingesetzt wird.
\; beende das exec.

cut erhält die Ausgabe von cat und trennt jede Zeile dieser Ausgabe mit dem leerzeichen (-d ‘ ‘) (Trennzeichen/delimitter -d), durch -f 1(nur das erste Feld) wird pro Zeile nur der Teil vor dem ersten Leerzeichen von cut auf der Standardausgabe ausgegeben

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Was muss inkludiert werden um printf()/strlen() zu nutzen?

A

printf() = #include

strlen()=#include

How well did you know this?
1
Not at all
2
3
4
5
Perfectly