Tags:C Interview Question, C++ Questions | 142 views
#include <stdio.h>
void dec2bin(long decimal, char *binary);
int main()
{
long decimal;
char binary[80];
printf(”\n\n Enter an integer value : “);
scanf(”%ld”,&decimal);
dec2bin(decimal,binary);
printf(”\n The binary value of %ld is %s \n”,decimal,binary);
Tags:C Interview Question, C++ Questions | 114 views
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char string[100];
int i,found=0;
printf(”Type a string : “);
gets(string);
for(i=0;i<strlen(string);i++)
if( isalpha(string[i]))
found++;
printf(”Number of characters: %d\n”,found);
return 0;
without using functions
#include<stdio.h>
#include<string.h>
void main()
{
char string[80];
char *s;
int <strong class=”highlight”>count</strong>=0;
int len;
printf(”Enter string\n”);
gets(string);
len=strlen(string);
printf(”%d”,len);
for(s=string;*s!=’\0′;s++)
{
if(*s==’ ‘)
{
count++;
}
else
break;
}
printf(”Number of words in string %d”,count);
}
[...]
Tags:C Interview Question, C++ Questions | 122 views
Here’s a simple function that does an infinite loop. It prints a line and calls itself, which again prints a line and calls itself again, and this continues until the stack overflows and the program crashes. A function calling itself is called recursion, and normally you will have a conditional that would stop the [...]
Tags:C Interview Question, C++ Questions | 125 views
Pointers
Pointer are a fundamental part of C. If you cannot use pointers properly then you have basically lost all the power and flexibility that C allows. The secret to C is in its use of pointers.
What is a Pointer?
A pointer is a variable which contains the address in memory of another variable. [...]