Lecture Introduction to computer and programming - Lecture No 21

This section addresses the question of program correctness functional programming. We visit the question of how to prove a program conect for the special case when it is written in a pure functional program-one that is state-less and relies instead on functional composition and recursion as a foundation for its semantics. | CSC103: Introduction to Computer and Programming Lecture No 21 Previous lecture 2 Dimensional array Initializing 2 Dimensional array Memory map of 2-D array Pointer and 2-D array Array of pointer Passing 2-D Array to a Function Today’s lecture outline Strings Null character Memory map of string String initialization Display string content Input string from user Passing a string to a function String A group of integers can be stored in an integer array Similarly a group of characters can be stored in a character array Character arrays are many a time also called strings Character arrays or strings are used by programming languages to manipulate text such as words and sentences Cont. A string is a one-dimensional array of characters terminated by a null ( ‘\0’ ) Each character in the array occupies one byte of memory The last character is always ‘\0’ Null character Represented by a back slash and a zero \0 It looks like two characters, but it is actually only one character Note that ‘\0’ and ‘0’ are not same. ASCII value of ‘\0’ is 0, whereas ASCII value of ‘0’ is 48 Memory allocation for string The elements of the character array are stored in contiguous memory locations The terminating null (‘\0’) is important, because it is the only way to know where the string ends A string not terminated by a ‘\0’ is not really a string, but just a collection of characters H A E S L E R \0 65508 65509 65510 65511 65512 65513 65514 65515 String initialization C will automatically insert \0 character at the end of the string. Memory allocated for name string is 8 bytes 7bytes for actual string and 1 byte for \0 character How string element are displayed Go to program Cont. K l i n s m a n 65508 65509 65510 65511 65512 65513 65514 65515 \0 65515 Go to program Pointer to string h e l l o \0 65508 65509 65510 65511 65512 65513 name[6] *ptr 65508 *ptr = *(65508) = h h ! = \0 true Program output h 65509 e ! = \0 true e 65510 l ! = \0 true l 65511 l ! = \0 true l 65512 o ! = \0 true o . | CSC103: Introduction to Computer and Programming Lecture No 21 Previous lecture 2 Dimensional array Initializing 2 Dimensional array Memory map of 2-D array Pointer and 2-D array Array of pointer Passing 2-D Array to a Function Today’s lecture outline Strings Null character Memory map of string String initialization Display string content Input string from user Passing a string to a function String A group of integers can be stored in an integer array Similarly a group of characters can be stored in a character array Character arrays are many a time also called strings Character arrays or strings are used by programming languages to manipulate text such as words and sentences Cont. A string is a one-dimensional array of characters terminated by a null ( ‘\0’ ) Each character in the array occupies one byte of memory The last character is always ‘\0’ Null character Represented by a back slash and a zero \0 It looks like two characters, but it is actually only one character Note that .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
308    10    1    13-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.