UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

8.6. Self-assessment questions

Check with these questions if you understood this document

  1. If we want to read a line from keyboard and to print it on the screen

    • We can use scanf or getline, because in the case that no space is given to store the result, both functions automatically allocate memory.

    • We use getline to read it and printf to print it. The memory allocated by getline is automatically managed by the operating system.

    • We use getline to read it , printf to print it and free to deallocate the memory allocated by getline.

  2. If we want to print the memory address where is stored the string char cadena[100];, we will use:

    • You cannot print the memory address of a string.

    • printf("%s\n",cadena);

    • printf("%p\n",cadena);

  3. We want to print the string char string[30]; with the printf function:

    • We do not have to inicialize string.

    • The string MUST include the '\0' termination char. If not, the program may produce a segmentation fault.

    • We can use string.printf("%s");