Contact: aviboots(AT)netvision.net.il
40,763 questions
53,138 answers
573 users
#include <stdio.h> #include <string.h> #define LEN 5 int main(void) { char arr[LEN] = {3, 8, 9, 0, 4}; memset(arr, 0, LEN); for (int i = 0; i < LEN; i++) printf("%3d", arr[i]); return 0; } /* run: 0 0 0 0 0 */
#include <stdio.h> #include <string.h> #define LEN 5 int main(void) { char arr[LEN] = { 3, 8, 9, 0, 4 }; memset(arr, -1, 3); for (int i = 0; i < LEN; i++) printf("%3d", arr[i]); return 0; } /* run: -1 -1 -1 0 4 */
#include <stdio.h> #include <string.h> #define LEN 7 int main(void) { char arr[LEN] = { 3, 8, 9, 0, 4, 5, 7}; memset(arr + 2, -1, 3); for (int i = 0; i < LEN; i++) printf("%3d", arr[i]); return 0; } /* run: 3 8 -1 -1 -1 5 7 */
#include <stdio.h> #include <string.h> #define LEN 5 int main(void) { int arr[LEN] = { 3, 8, 9, 4, 7}; // int memset(arr, 0, LEN); for (int i = 0; i < LEN; i++) printf("%3d", arr[i]); return 0; } /* run: 0 0 9 4 7 */
#include <stdio.h> #include <string.h> #define LEN 5 int main(void) { int arr[LEN] = { 3, 8, 9, 4, 7}; // int memset(arr, 0, LEN * 4); // int for (int i = 0; i < LEN; i++) printf("%3d", arr[i]); return 0; } /* run: 0 0 0 0 0 */