Please help in memset

#include <algorithm> 
#include <vector>
#define ll long long int 
#define nl '\n'
#define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std; 



int main()
{
    int t;
    cin>>t;
while(t--){
    ll kd;
    cin>>kd;
    
    char str[kd];
    memset(str, 'd', kd);
   cout<<str<<endl;
   //int it=0;
   //it=s.find(str);
}
  
   
    


return 0 ;



}
why this code gives random output @ssjgz
input->
3
4 
2 
1

Read about memset. You can not use memset for any value.

1 Like