troubleshooting Question

problem with memset.

Avatar of bhombal
bhombal asked on
C
4 Comments1 Solution440 ViewsLast Modified:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main(){
  int i[50],j,k;
       clrscr();
           printf("Enter value for initialization : ");
          scanf("%d", &j);
         memset(i,j,10);
                 
              for (k=0;k<10;printf("%d\n",i[k++]));
           
          getch();
}

In Turbo c++ (ver.3) for the Above code if I provide value 1 for j then it is giving output ambiguously. Instead of assigning 1 to each subscript it multiplies j with the value of i[k].
e.g.,
       if j=1
     [before Initialization][after Initialization][should be]
     i[k]=257          257              1    
     i[k]=0               0                   1
     i[k]=1               1              1

     like that.

proper guidance expected.
ASKER CERTIFIED SOLUTION
GnarOlak

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros