Yahoo Answers is shutting down on 4 May 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Sheer
In C, to display semicolon in format string of printf(), do we use \; or we simply use ;?
Which one of the following is correct in C:
printf("A semicolon looks like \;");
OR
printf("A semicolon looks like ;");
Isn't semicolon a special character in C just like " which needs a \ ahead of it to be displayed in the format string?
3 AnswersProgramming & Design8 years agoC : Please explain how this little code snippet calculates a^b (a raised to power b) using recursion.PLZ!?
The following program (taken from a book) calculates the power of a number "a" raised to "b".It uses recursion to do that.But even though I tried hard to comprehend how it is working, I still fail to see the logic.I feel real bad that I can't understand the logic behind this simple program.So please explain how it is functioning.I am sure it won't be much bother to you.Thanks!!
/* power of "a" calculation using recursion*/
#include<stdio.h>
int main()
{
int a=5,b=4;
printf("%d",foo(a,b));
}
int foo ( int x , int n){
int val=1;
if(n>0){
if (n%2 == 1) val = val *x;
val = val * foo(x*x , n/2);
}
return val;
}
6 AnswersProgramming & Design8 years agoमछलियों को भी नसीब होता है कफन--What does this mean in Hindi or Urdu?
2 AnswersLanguages8 years agoWhat is the difference between Abstract Data Type(ADT) and Aggregate data types?
I understand what each term mean,but as is given in the following link, there seems to be no clear distinction between the two.
http://www.cs.uregina.ca/Links/class-info/cplusplu...
So can you kindly tell me the strict difference between the two, or if one is a subset of other, then which one is the subset here? For one thing I know, arrays are considered as data-structures too and in that link arrays are called aggregate data types as well.So please clear the confusion for me.Thanks. (And yes, it's nice to be back into Yahoo Answers Programming Section after so many weeks)
2 AnswersProgramming & Design8 years agoHow to find a publisher for my first book?What are the terms & conditions for royalty & payments?
I would appreciate if you can answer my question in a numbered format
1)How does a first-time author get his book published from a reputed publisher?Or first-timers have to reconcile with lesser-known publishers?
2)Is a first-time author paid royalty if his book sells well?Or is he given a lump-sum in the beginning?Is a lawyer involved in the agreement?
3)What is a bestseller?How much copies the book should sell to fetch a fortune for the author and the publisher?
3 AnswersBooks & Authors8 years agoIs a knowledge of Topology(Mathematics) of any normal,practical use in Computer Science/Engineering?
The full-fledged Computer Science curriculum that I follow stresses on Discrete Mathemtics,Linear Algebra,Numerical Methods and Probability,but it expects just a basic understanding of Calculus.Yet,since I realize that Calculus DOES certainly has numerous applications in Computer Science and Programming (And also because I am already familiar with basic calculus),I plan to undertake an advanced calculus course on my own.But I have to question myself --"Where to stop in Maths?".I don't have the luxury of time and effort that one needs go into pure Maths as after my Masters I'll have to concentrate on stuff that will be of use in professional life of an engineer.All subjects in Maths I have touched on yet--Discrete Maths,Linear Algebra,Algebra,Calculus--They all h ave tangible use in Computer Science (And programming).So can you kindly tell me if Topology is in the realm of subjects like Advanced Set Theory,Real Analysis,Chaos etc which is best-suited for those who have Maths as a full-fledged career? I am asking this because I love to dabble with Maths in my leisure time and if Topology is of any possible practical use,then I would like to pursue it.If it's too "abstract" or "fuzzy" then I would rather not.I saw a few video lectures and a book, and it seems very daunting and that it will take a great deal of time.So please advice me, is it worth it?Unlike Discrete Maths or Calculus, will it be an unnecessary thing to pursue for a Computer Science guy?
1 AnswerMathematics9 years agoIs a knowledge of Topology(Mathematics) of any normal,practical use in Computer Science/Engineering?
The full-fledged Computer Science curriculum that I follow stresses on Discrete Mathemtics,Linear Algebra,Numerical Methods and Probability,but it expects just a basic understanding of Calculus.Yet,since I realize that Calculus DOES certainly has numerous applications in Computer Science and Programming (And also because I am already familiar with basic calculus),I plan to undertake an advanced calculus course on my own.But I have to question myself --"Where to stop in Maths?".I don't have the luxury of time and effort that one needs go into pure Maths as after my Masters I'll have to concentrate on stuff that will be of use in professional life of an engineer.All subjects in Maths I have touched on yet--Discrete Maths,Linear Algebra,Algebra,Calculus--They all h ave tangible use in Computer Science (And programming).So can you kindly tell me if Topology is in the realm of subjects like Advanced Set Theory,Real Analysis,Chaos etc which is best-suited for those who have Maths as a full-fledged career? I am asking this because I love to dabble with Maths in my leisure time and if Topology is of any possible practical use,then I would like to pursue it.If it's too "abstract" or "fuzzy" then I would rather not.I saw a few video lectures and a book, and it seems very daunting and that it will take a great deal of time.So please advice me, is it worth it?Unlike Discrete Maths or Calculus, will it be an unnecessary thing to pursue for a Computer Science guy?
1 AnswerProgramming & Design9 years agoIs a knowledge of Topology(Mathematics) of any normal,practical use in Computer Science/Engineering?
The full-fledged Computer Science curriculum that I follow stresses on Discrete Mathemtics,Linear Algebra,Numerical Methods and Probability,but it expects just a basic understanding of Calculus.Yet,since I realize that Calculus DOES certainly has numerous applications in Computer Science and Programming (And also because I am already familiar with basic calculus),I plan to undertake an advanced calculus course on my own.But I have to question myself --"Where to stop in Maths?".I don't have the luxury of time and effort that one needs go into pure Maths as after my Masters I'll have to concentrate on stuff that will be of use in professional life of an engineer.All subjects in Maths I have touched on yet--Discrete Maths,Linear Algebra,Algebra,Calculus--They all h ave tangible use in Computer Science (And programming).So can you kindly tell me if Topology is in the realm of subjects like Advanced Set Theory,Real Analysis,Chaos etc which is best-suited for those who have Maths as a full-fledged career? I am asking this because I love to dabble with Maths in my leisure time and if Topology is of any possible practical use,then I would like to pursue it.If it's too "abstract" or "fuzzy" then I would rather not.I saw a few video lectures and a book, and it seems very daunting and that it will take a great deal of time.So please advice me, is it worth it?Unlike Discrete Maths or Calculus, will it be an unnecessary thing to pursue for a Computer Science guy?
1 AnswerProgramming & Design9 years agoIf US Presidential election 2012 is on 6th November,when will be the final result out?
What is the date by which the winner of the election be known?By night of 7th November or what?
2 AnswersPolitics9 years agoIn C, how to display the output of a program both to a file and to the console(stdout)?
Say I have the following program that simply outputs "Hello Yahoo Answers":
//DEMO
#include<stdio.h>
int main()
{
printf("HELLO Yahoo Answers");
}
Now I want to display it both to the screen and to a file "output.txt".So I enter the following command in the command prompt(I use CodeBlocks on Windows XP and have configured it to work on command prompt too):
demo.exe>>output.txt>>stdout
IT JUST DOESN'T WORK!!! Please tell me how to do it,ie how to output the same thing that I see on my screen(When i run the program),simultaneously to a text file?
3 AnswersProgramming & Design9 years agoIn Unix,does a child process execute only the code segments that come AFTER the fork() call that created it?
Consider a program outline like this :
int main()
{
/*Code before fork()
blah blah
*/
pid=fork();
/*Code after fork()
blah blah
*/
}
Does the child process created due to fork() in such a program execute only the code segment tagged "Code after fork()" and it avoids the code segment tagged "code before fork()"? I want your confirmation, even though my gut feeling is that only the portion of the code coming after the fork() statement will be executed by the child process.PLEASE ANSWER.
And while we are at it, can you confirm if the "2^n-1" formula holds for questions like the following :
Question: If a process forks thrice as follows, what will be the total number of child processes as a result of it?
fork();
fork();
fork();
I solved it graphically on paper and the answer according to me comes to be 7.But in questions like these, when we are told that the process forks "n" times, can we safely calculate the total number of child processes as "2^n-1"? (Finding the answer graphically by drawing the whole thing takes too much time even as "n" increases"...
These are my first steps into operating systems, so please help me with your answer.THANKS!!
2 AnswersProgramming & Design9 years agoWhat does "until EOF is reached" mean in context of the following definition of gets() function in C?
Sourced from the following link, what does it mean when we say "gets() reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached."?
My confusion is that, since we are reading the string from the keyboard, where does EOF come into play?I mean, we end our entry with an "Enter" key ('\n'") only when entering input from keyboard, and EOF is used in the context of files stored on the hard disk.Isn't it? Or gets() can be used to read from files too?Please clear this confusion for me. Thanks.
2 AnswersProgramming & Design9 years agoHENNI,OOPS:Please diagnose why this well-compiled C program says "Program Encountered Problem" & won't run.?
The Following program is copied from a book & compiles successfully.It is an implementation of queue using linked list.But when I run it on CodeBlocks,it says "Program encountered a problem and needs to close".It won't tell anything more.But when I compile it on TurboC++,it shows the message "General Protection Exception--Processor fault" and then highlights in blue lines 30 & 31,which I have pointed out with comments in the code below.The higlighted lines are :
q->front=NULL;
q->rear=NULL;
But still,I am not sure if those lines are the issue.So please diagnose why this program taken from the book is not running.(Out of nearly 80 programs in the book,I got hardly a few typos,so I don't think the code itself is faulty) (And Henni,I don't use "void" return type for main() function anymore,but still using it in this program as I have copied it for your consideration as it was in the book.It doesn't run even if I change it to "int".SO PLEASE DIAGNOSE THE PROBLEM BY RUNNING IT IN YOUR COMPILER)
//Prog2:Implementation of queue using linked list
#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *next;
};
typedef struct node *qptr;
typedef struct
{
qptr front,rear;
}*queue;
int IsEmpty(queue);
void Insert(queue,int);
int Delete(queue);
void Display(queue);
void main()
{
queue q=NULL;
int x;
char ch='1';
q->front=NULL; //NOTE: TurboC++ Highlights this line
q->rear=NULL; //NOTE: TurboC++ Highlights this line
while(ch!='4')
{
printf("\n 1-INSERT");
printf("\n 2-DELETE");
printf("\n 3-DISPLAY");
printf("\n 4-QUIT");
printf("\n\nEnter your choice:");
fflush(stdin);
ch=getchar();
switch(ch)
{
case '1':
printf("\nEnter the element to be inserted:");
scanf("%d",&x);
Insert(q,x);
break;
case '2':
x=Delete(q);
printf("\nThe deleted element is %d\n",x);
break;
case '3':
Display(q);
break;
case '4':
break;
default:
printf("\nwrong choice!Try again");
}
}
}
int IsEmpty(queue q)
{
if(q->front==NULL)
return 1;
else
return 0;
}
void Insert(queue q,int x)
{
qptr temp;
temp=(qptr)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\nout of memory space");
exit(0);
}
temp->info=x;
temp->next=NULL;
if(q->rear==NULL)
q->front=temp;
else
(q->rear)->next=temp;
q->rear=temp;
}
int Delete(queue q)
{
qptr temp;
int x;
if(IsEmpty(q))
{
printf("\nqueue empty");
exit(0);
}
temp=q->front;
x=temp->info;
q->front=temp->next;
if(q->front==NULL)
q->rear=NULL;
free(temp);
return x;
}
void Display(queue q)
{
qptr ptr;
ptr=q->rear;
printf("\nThe elements in the queue are\n");
if(ptr==NULL)
{
printf("\nqueue empty\n\n");
return;
}
for(ptr=q->front;ptr!=NULL;ptr=ptr->next)
printf("%d\n",ptr->info);
}
-----------------------------------
/////THE FOLLOWING IS DESIRED OUTPUT FOR A SAMPLE INPUT:
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 1
Enter the element to be inserted : 11
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice : 1
Enter the element to be inserted : 33
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 1
Enter the element to be inserted : 22
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 3
The elements in the queue are
11
33
22
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 2
The deleted element is 11
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 3
The elements in the queue are
33
22
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice:2
The deleted element is 33
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 3
The elements in the queue are
22
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 2
The deleted element is 22
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice: 3
The elements in the queue are
queue empty
1-INSERT
2-DELETE
3-DISPLAY
4-QUIT
Enter your choice : 4
2 AnswersProgramming & Design9 years agoC: what's wrong with "char name[20]="Seattle",(*ctr)[]=name;"?Is it wrong way to declare a string pointer?Why?
Please consider the following little program and clear the 2 confusions I encountered due to it thereafter.
#include<stdio.h>
int main()
{
char name[20]="Seattle",(*ctr)[]=name; //Shows warning
//char name[20]="Seattle",(*ctr)[]=&name; //This works fine without warning
*ptr=name; //works fine as expected
printf("%s,%s",ptr,ctr);
}
OUTPUT: Seattle,Seattle
Confusions:
1)Is "char (*ctr)[]=&name;" also a correct way to declare a pointer to a string,other than the conventional way?I base it on my argument on the fact that we declare a pointer to integer array as "int (*ptr)[]"? If not, then why in the program it works fine as a string pointer WITHOUT a warning?PLZ shed some light on it.
2)Why does taking out the "&" above as "char (*ctr)[]=name;" instead of "char (*ctr)[]=&name;" shows a warning (even though output is same)?If there has to be warning, shouldn't it be for the case where we use "&" before a string name?I mean, why does "char (*ctr)[]=name" show warning while "char (*ctr)[]=&name" doesn't even though we are supposed to give only string names to string pointers?
3)Why does "char (*ctr)[]=&name;" work at all?That too without even a warning? Isn't it silly to use a "&" before a sting name in assigning address because the string name "name" itself is the base address and we assign string names to string pointers without using "&" as we do with variables?
PLEASE give your answers
1 AnswerProgramming & Design9 years agoHenni,Jonathan,Ratchetr,Unca Alby,Oops, In C, why is "int arr[]={15,25,35},(*ctr)[]=arr;" showing problems?
Please see the following program and kindly explain the discrepancies I have found when I run it.It will help me a lot in my understanding of pointers.Thanks.
#include<stdio.h>
int main()
{
int i,arr[]= {15,25,35,45},*ptr=arr,(*ctr)[]=arr; //ALERT: Shows warning
for(i=0; i<=3; i++)
printf("%d\n",*(ptr+i));
/*
for(i=0;i<=3;i++)
printf("%d\n",*(ctr+i));//ALERT: Shows error unlike *(ptr+i)
*/
printf("\n%u,%u",ptr,ptr+1);
printf("\n%u",ctr); //shows same output as "ptr" above
//printf("\n%u",ctr+1); //ALERT: Shows error
printf("\n%d,%d",*ptr,*(ptr+1));
printf("\n%d",*ctr); //HELP!!Shows same output as "ctr" above
//printf("\n%d",*(ctr+1)); //Shows error
}
1)Why "ctr+1" shows error "invalid use of array with unspecified bounds" in 4th printf() whiile ctr works fine in the 3rd printf()?"ctr" is assigned the same address value as "ptr" and like "ptr+1"(which works fine) it too is supposed to give the value of the next pointer when we write "ctr+1".What goes wrong here?
2)If "*ctr" works,then why doesn't "*(ctr+i)" or "*(ctr+1)" work?After all "*(ptr+i)" or "*(ptr+1)" works as good as "*ptr" does?For "*(ctr+i)" and "*(ctr+1)" the following error is there?
"error: invalid use of array with unspecified bounds|"
3)Why are values of "ctr" and "*ctr" same in 3rd and 6th printf()'s respectively?Those values are same even if use same format specifier(%u or %d).Isn't "*ctr" supposed to be the same as "*ptr",wich should be the first element of the array.Ignoring the previous line for the moment, HOW ON EARTH COULD "ctr" and "*ctr" have the same value?
4)Why doesn't "*ctr" print 15(first element) as "*ptr" does?After all ptr and ctr are both successfully assigned base address of array "arr" as is evident from the output of their values in lines "printf("\n%u,%u",ptr,ptr+1);" and "printf("\n%u",ctr);" respectively above?
5)When I use "(*ctr)[]=arr" instead of "("ctr)[]=&arr" I get the following warning(not error)
"warning: initialization from incompatible pointer type|"
but outputs are same.Why the warning?Isn't (*ctr)[]=arr supposed to be the correct one as "arr" assigns base address of array as expected?In arrays we don't use the "&" operator to assign address, do we?Then why is "=arr" showing warning but "=&arr" works fine?
6)Finally, a trivial question.Why does the program shows same results if we interchange "%u" and "%d" at will?Isn't %u supposed to be different from %d because in %u the first bit is considered the sign bit and not considered part of the number?
////PS: You may like to answer it in the context of bit/section(1) of the following question I had posted a day back.
3 AnswersProgramming & Design9 years agoIn C,how to determine the end of an integer,float or "string" array(not string)?End,not size allocated.?
In an integer array,float array and string array as in the following ,how to we find the end of the array?
int nums[10]={2,4,6,8,10};
float rates[15]={2.5,3.5,6.48,8.23};
char names[10][15]={"UAE","USA","UK"};
I mean, in all three cases above, the capacity of the array is much more than the number of elements.So if we are using a "for" loop to print out the elements of each of the above arrays, what should we compare the "for" loop counter "i" with? How can we know we have reached the last element and the rest space of the array is vacant after that?Do we have a end mark like "\0" as we have in the case of a string?(In the third case above, as you may notice it's not a string but an array of strings)
I hope you got what i am trying to ask......how to determine the end of an integer,float, or string array (so that we can use that in the evaluation of a loop counter or loop index,among other uses)?What is the solution?Please take a few miinutes to answer.Thanks.
3 AnswersProgramming & Design9 years agoBoolean Function: What does "There are 2^(2^k) functions for every k" mean in following?How do we derive that?
What does the following mean?
-------------------
Every k-ary Boolean formula can be expressed as a propositional formula in k variables x1, …, xk, and two propositional formulas are logically equivalent if and only if they express the same Boolean function. There are 2^(2^k) k-ary functions for every k.
http://en.wikipedia.org/wiki/Boolean_function
----------------------------
I understand what a propositional formula in k variables is (say x1 to xk) but how does it equal to the formula given 2^(2^k) ? HOW TO DERIVE IT?Do we get that by combination of the logical operators like "AND","OR","NOR"?Like:
1)x1 AND x2 AND x3 OR x4 .......
2) x1 OR x2 AND x3 AND x4......
and so on?
Please explain it to me.I feel bad I can't grasp this preliminary thing.Thanks.
2 AnswersMathematics9 years agoC: When declaring "int num[9];" does num[9] makes sense only in declaration as at maximum it can be num[8]?
I mean, the array of size 9 starts with "int[0]", hence it ends in "int[8]".So beyond the declaration statement, there is no such thing as "int[9]". So am I right to say that "num[9]" makes sense only in the declaration statement?
2 AnswersProgramming & Design9 years agoC:If size of an array must be known at time of declaration,why is "char name[][20];" valid?
I read in my book that "char name[];" is invalid as array size must be known at time of declaration.But it says "char name[][10];"is valid as only the second index needs to be known.Why is it so?Doesn't the unknown first index mean that the size of the array itself is unknown?Why then is it valid in C?
2 AnswersProgramming & Design9 years agoC : Why is "extern" needed for functions in case of multi-file source code,with one main() function?
Suppose we have a program whose source code is split into two ".c" files "major.c" and "minor.c"
//major.c
#include<stdio.h>
#include "minor.c"
extern void display();
int main()
{
display();
return 0;
}
--------------------
//minor.c
void display()
{
printf("Hello Yahoo");
}
If I compile it from the command prompt using "gcc -o major.exe major.c minor.c" then it kinda appends minor.c to major.c(just as we want) and compiles it as one file into major.exe.Also,if I compile "major.c" from Codeblocks GUI, then again it compiles fine and generates major.exe.Now PLEASE see if you can clarify the following for me:
1)Do we need any function, whose definition is in another file (but part of same program) to be tagged "extern"? The above program works fine even if we don't use "extern" while declaring display() in "major.c".One contributor had told me that "extern" tells the compiler that the definition of the function is in another file.But why then it works without extern?And if commands like "gcc -o major.exe major.c minor.c" and "#include "minor.h" essentially joins together files that constitute the program, then why we need extern AT ALL(for functions as well as variables) as after all, we are essentially dealing with one large file and the "definition in another file" thing means little?
2)In the above code, it works fine if I compile "major.c".But when I compile minor.c, it throws some errors quite expectedly as the prinf() there has no prototype (as there is no stdio.h there).Had minor.c been a large file, there might be many more errors.Can you tell me how we deal with this scenario? I mean,USING THE GUI how do we compile the files of the program which don't have the main() function to check if they are correct and have no errors?Say my program had 5 files, how do I compile those which don't contain the main() function? In this case,will it be wrong for me to use "#include<stdio.h>" again in "minor.c" as it's already in "major.c"?
3)Do we need to use "extern" (if at all it's necessary) and "#include "minor.c" in "major.c" even if we are using the "Project mode" option in Codeblocks Gcc GUI?Or in Project mode we can use multiple files for the program as if they are part of one large file without worrying about hash-including or using "extern", and it's the IDE's job to join them together?
3 AnswersProgramming & Design9 years ago