How to find time complexity of a program and various algorithm??
Can anyone suggest me any reading on this topic?
User Profile
Collapse
-
time complexity of a program
-
how does a C program gets executed
I want to know how a C program gets executed. I mean what happens when we compile.
What steps compiler follow for successful execution of a program?
What happens at compile time and run time?
Can u please give me any link on internet which explains these things properly. -
The compiler didnot complain.
I just asked it to know if this is possible there is no other reason for that. -
interchanging int and static
static int i;
int static i;
Can i interchange static and int while defining a variable. -
You mean the difference gives the number of elements between two pointersLeave a comment:
-
I made a mistake in asking the question
#include <stdio.h>
int main(void)
{
int a=1,*p=&a,*q=p;
printf("%p %p",p,q);
p++;
printf("\n%p",p-q);
}
Why does this prints 1 but i expected it to print 4.
If p initially points to 1000 and q also to 1000 after p++ p will ;point to 1004
and when i take the difference it sud print 4 but why...Leave a comment:
-
#include <stdio.h>
int main(void)
{
int a=1,*p=&a,*q=p;
printf("%p %p",p,q);
p++;
printf("\n%p",p );
getch();
}
LOok at this code snippet.
Why does this gives 1 i thought it will print 4 on my machine as int takes 4 bytes on my machine.
Also if i use this line
printf("\n%p",( char*)p-(char*)q);
it prints 4 ....Leave a comment:
-
two pointers same address
#include <stdio.h>
int main(void)
{
int a=1,*p=&a,*q=p;
printf("%p %p",p,q);
return 0;
}
I have a doubt in the above code. There are two pointers p and q .when i print the address of p and q it comes out to be same. how is this possible. I know that both are pointing to same location but still they are two different variables then address corresponding to them sud also be different... -
donbock
I read in K&R so i thought its possible to do such thing
This is quote from K&R
"If one is sure that the elements exist, it is also possible to index backwards in an array; p[-1], p[-2], and so on are syntactically legal, and refer to the elements that immediately precede p[0]. Of course, it is illegal to refer to objects that are not within the array bounds."
chapter 5 (5.3 Pointers and Array)...Leave a comment:
-
Banfa
You said that it is not hte right way to handle negative indexes in array then what should be the right way to access a negative index.
Take a simple example
int a[10]={1,2,3,4,5};
suppose i further declare a[-1]=0 and then use it in the code will that be a wrong thing to do?
In the original question i have padded the array and then using it.Is that a wrong thing?Leave a comment:
-
UB or not
first code
Code:char * f(void){ char a[]="C is a very good language"; return a; } int main() { char* b= f(); printf("%s",b); getchar(); }
Code:int f(void){ int x=9; return x; } int main() { int i=f(); printf("%d",i); getchar();
-
negative index in array
say i have a two dimensional array a[512][512]. There is one more 2D array
b[512][512]. The algorithm is like this depending on value of a[i][j] i have compare b[j][k] with two of its neighbour.
This is a part of that algorithm
if(a[j][k]==0)
{
if(b[j][k]>=b[j][k+1] && b[j][k]>=b[j][k-1])
some code here
}
the problem is when k=0... -
assignment operator and copy constructor
class A
{
public:
A() {cout << "1";}
A operator=(const A&){cout << "2"; return *this;}
A (const A&) {cout << "3";}
};
int main()
{
A a1;
A a2 = a1;//line 1
a2 = a1;//line 2
}
pls explain which functions will be called in line 1 and line 2 and why?? -
Undefined behaviour
why a[i]=i++ is an UB. here the value of i has changed only once.
also i think there is no ambiguity in the value of i because in assignment operator the RHS part is evaluated and then assigned to LHS . so why this is an UB. -
actually i interpreted int(*p)[5] wrongly.that was the reason for that confusion.
No confusions now .Thanx.Leave a comment:
-
pointer to an array
In general int (*p)[3] means p is a pointer to an array which stores 3 integers.
Correct me here if i am wrong.
look at this code
int (*p)[3]={1,2,3};
Is the above statement valid?If not then why.pls explain it.
Also what will int (*p)[3] hold? i mean an int pointer or an int -
Car parking example was awesome.Really a gr8 explanation
A big thanx to you Banfa.You are gr8.Leave a comment:
-
Banfa
i read ur above post and it cleared my doubt but still there are some doubts somewhere in my mind.pls answer it.
Let us say i have int a[3]={1}
.Its first element i.e. a[0] will be stored at some location say 23FF60.If i write &a[0] i will get this value(23FF60) again if i write a i will get the same value.
My question is why are address of a[0] (i.e. &a[0]) and address of a(&a) are stored at the...Leave a comment:
-
Banfa
You mean to say address of a[0] and a are stored at the same location.
Also what should &a+2 yield??Leave a comment:
-
array
int a[10];
why does
printf("%p",a); and printf("%p",&a) ;
print the same result.
also printf("%p",&(a )); //this works fine
but printf("%p",.&( a+2));//results into error.
No activity results to display
Show More
Leave a comment: