ethico's blog

By ethico, history, 10 months ago, In English,

Hey fellows,

-->i want to know about memset,how its work,because when i put 0 or -1 as like as memset(a,-1,a.sizeof(a)) or memset(a,0,a.sizeof(a)),i am getting values,but if i put any other random number,why it is showing garbage values?

--> moreover,can u guys suggest me online best website for learning **cpp(c++).

Read more »

 
 
 
 
  • Vote: I like it
  • -9
  • Vote: I do not like it

By ethico, history, 11 months ago, In English,

usually when i started coding and started learning about string array or normal array ,i used to work with string array or array by typing strlen() or size() in the for loop condition.

for(int i=0;i<strlen();i++)
{
    statement;
}

but its a totally wrong way to set up the condition.because normally if my algorithms complexity is O(n),and i use strlen() it,my time complexity will become O(n^2). **** this happens because every time for loop come to check the condition it will start checking what is the string length is,so total complexity will become n*n = n^2 **** so to avoid this kind of situation ,declare integer variable n= strlen(),and then put the code like this

int n= strlen();
for(int i=0;i<n;i++)
{
    statement;
}

i hope this will be helpful :).

Read more »

 
 
 
 
  • Vote: I like it
  • +35
  • Vote: I do not like it