Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,990 questions

51,935 answers

573 users

How to set values to int array using memset in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main() {
    int arr[5] = {1, 2, 3, 4, 5};

    // void *memset(void *str, int c, size_t n) 
  
    // str − A pointer to the block of memory to fill

    // c − The value to be set

    // n − The number of bytes to be set

    memset(arr, 0, 8); // set 0 to first two int values (int - 4 bytes)

    for (int i = 0; i < 5; i++) {
        printf("%d ", arr[i]);
    }
  
    return 0;
}



/*
run:

0 0 3 4 5 

*/

 



answered Apr 2, 2024 by avibootz

Related questions

1 answer 103 views
103 views asked May 29, 2024 by avibootz
1 answer 106 views
106 views asked Dec 17, 2022 by avibootz
1 answer 88 views
88 views asked Nov 11, 2022 by avibootz
5 answers 182 views
182 views asked Nov 11, 2022 by avibootz
1 answer 194 views
2 answers 181 views
...