C debugging interview questions
C debugging questions with answers
1. Create a C program to initiate the shutdown of a Windows operating system using Turbo C. Save the following code in a file named 'close.c':
void main(void)
{
system("shutdown -s");
}
After saving the file, compile and execute the program in Turbo C. Close the Turbo C compiler and navigate to the directory where you saved 'close.c' (default directory: 'c:\tc\bin'). Double-click the executable file ('close.exe'). After a short delay, your Windows system will initiate a shutdown.
2. Compose a scanf statement capable of capturing an entire line of text, including spaces.
Answer:
void main() {
char a[30];
clrscr();
scanf("%[^\n]",a);
printf("%s",a);
getch();
}
3. Given the string
"MATCHMAKING", write a program to read the string from the terminal
and display the same in the following formats:
(a) MATCH MAKING
(b) MATCH
MAKING
(c) M.M.
4. I need it to write a C/C++ program that
connects to a MySQL server and displays the global TIMEZONE.
Answer:
I can provide you with a simple example in C++ using the MySQL Connector/C++ library. Please note that you need to have the MySQL Connector/C++ installed and linked properly with your project.
Here's a basic example:
#include <mysql_driver.h>
#include <mysql_connection.h>
int main() {
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
try {
driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "your_username", "your_password");
// Connect to the MySQL server
con->setSchema("information_schema");
// Execute a query to get the global timezone
sql::Statement *stmt = con->createStatement();
sql::ResultSet *res = stmt->executeQuery("SELECT @@global.time_zone AS time_zone");
// Display the result
while (res->next()) {
std::cout << "Global Timezone: " << res->getString("time_zone") << std::endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
std::cerr << "# ERR: SQLException in " << __FILE__;
std::cerr << "(" << __FUNCTION__ << ") on line " << __LINE__ << std::endl;
std::cerr << "# ERR: " << e.what();
std::cerr << " (MySQL error code: " << e.getErrorCode();
std::cerr << ", SQLState: " << e.getSQLState() << " )" << std::endl;
}
return 0;
}
Make sure to replace "tcp://127.0.0.1:3306"
, "your_username"
, and "your_password"
with your MySQL server details.
Remember to include the necessary MySQL Connector/C++ headers and link against the library when compiling. The actual connection details (server address, username, and password) will depend on your MySQL setup.
5. A string (example "I am writing an email") is entered through the keyboard, write a program in C to
get its reverse in a column as output i.e.:
email
an
writing
am
Answer:
void main()
{
char str[20];
char *ptr=str,*temp;
int i=0,j;
clrscr();
scanf("%[^\n]",str);
while(*ptr){
i++;
ptr++;
}
for(j=0;j
if(*ptr==' ')
{
temp=ptr;ptr--;temp++;
while((*temp!=' ')&&(*temp!='\0')) {
printf("%c",*temp);
temp++;
}
printf("\n");
}
else
{
ptr--;
}
}
while(*ptr!=' ') {
printf("%c",*ptr);
ptr++;
}
getch();
}
6. I want a C
program to check whether a string is a palindrome or not where the string to be
checked is passed as command line argument during execution.
Answer:
#include<string.h>
void main(int counter,char**string)
{
char *rev;
char str[15];
int i,j;
clrscr();
strcpy(str,string[1]);
printf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe
string is not a palindrome");
else
printf("\nThe
string is a palindrome");
getch();
}
7. How to write a c program to display
the source code of the program.
Answer:
If source code is available
#include<stdio.h>
void main()
{
char str[70];
FILE *p;
clrscr();
if((p=fopen("mod.c","r"))==NULL)
{
printf("\nUnable t open file
string.txt");
exit(1);
}
while(fgets(str,70,p)!=NULL)
puts(str);
fclose(p);
getch();
}
8. Swapping of two number without using
third variable
Answer:
void main()
{
int a=5,b=10;
clrscr();
//process one
a=b+a;
b=a-b;
a=a-b;
printf("a=
%d b= %d",a,b);
//process two
a=5;b=10;
a=a+b-(b=a);
printf("\na=
%d b= %d",a,b);
//process three
a=5;b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na=
%d b= %d",a,b);
//process four
a=5;b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na=
%d b= %d",a,b);
//process five
a=5,b=10;
a=b+a,b=a-b,a=a-b;
printf("\na=
%d b= %d",a,b);
getch();
}
9. How to convert decimal to binary in c
program?
Answer
void main()
{
long int m,no=0,a=1;
int n,rem;
clrscr();
printf("Enter
any decimal number->");
scanf("%d",&n);
m=n;
while(n!=0)
{
rem=n%2;
no=no+rem*a;
n=n/2;
a=a*10;
}
printf("The
value %ld in binary is->",m);
printf("%ld",no);
getch();
}
10. Write a
program to accept character and integer n from user and display next n
character
Answer:
void main()
{
char c;
int n,i;
clrscr();
printf("insert
one character and integer : ");
scanf("%c%d",&c,&n);
for(i=c+1;i<=c+n;i++)
printf("%c
",i);
getch();
}
Output:
insert one character and integer : c 4
d e f g
C debugging questions
Debugging questions in c
41 comments:
For the 1st point, no need to use Turbo C compiler, just add :
#include
at the beginning of your programm and you're done.
#include
stdlib
for shutting down ur system do one thing.
type shutdown -s on cmd.
then ur computer will shutdown within 1 minute.
#include
main()
{
char *p;
static int arr[]={2,3,4};
p=arr;
p=(char *)((int *)(p));
printf("%d",*p);
p=(int *)(p++);
printf("%d",*p++);
}
o/p=2,0 pls can any1 explain??
line 1 -declaration of pointer p
line 2 -declaration of int arr
line 3 -pointer p will point out the
value 2
line 4 -pointer p is typecasted in int pointer and then again typecasted in char pointer still it point out 2
line 5 -value of p is printed which is 2
line 6 -p is incremented which is address and now it does not point out 2 and then it contains garbage and typecasted in int pointer
line 7 -then the value of p is printed which is 0
this is great men
for 8th question
void main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d%d",a,b);
printf("after swapping");
a=(b-a)+a;
b=(a-b)+b;
printf("%d%d",a,b);
getch();
}
a = 5, b = 10,
a = (10-5)+5 = 10;
b = (10-10)+10 = 10;
so using this you can't swap two number.
void main()
{
int a=10,b=5;
int *x,*y;
x=&b;
y=&a;
printf("a=%d b=%d" ,*x,*y);
getch();
}
#include
void main()
{ long int n;
int i,r=0,sum=0,sum2=0,r1;
clrscr();
scanf("%ld",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
if(sum>10)
{
while(sum>0)
{ r1=sum%10;
sum2=sum2+r1;
sum=sum/10;
}
}
else
{
printf("%d",sum);
return 0;
}
printf("%d",sum2);
getch();
}//65536
Hi All, Please help me for creating a C program & I am new for C development.
The Task is given by my Team leader , The task description is given below :
We need an C program that, when given a table name and database name as arguments, will query the informix & Postgres system tables to get all permissions granted to various users on that table. The program will then generate sql statements to grant all these permissions on the table and write these statements to a file which can be run later.
From my basic research, the information needed can be got from the tables "systabauth" and "syscolauth", the former for table-level privilèges and the latter for column-level privilèges, if any. You will need to do some more research to find out how exactly to get the required information out of these tables.
YOU CAN USE THIS METHOD
void main()
{
int a,c;
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping a=%d and b=%d",a,b);
getch();
}
}
pls explain 5th nd 6th question...!
Why it's not giving 3 if p is incrementing..Please explain
A=5
B=10
Great job. It’s wonderful. You can make information unique and interesting.
Angular JS Training in Chennai | Certification | Online Training Course | Angular JS Training in Bangalore | Certification | Online Training Course | Angular JS Training in Hyderabad | Certification | Online Training Course | Angular JS Training in Coimbatore | Certification | Online Training Course | Angular JS Training in Online | Certification | Online Training Course
FOXZ88.NET online casino website คาสิโนออนไลน์ Global standard 2020-2021.
Ufabet betting online gambling reminiscent of UFASCR.COM Baccarat.
UFABET football betting website, the big brother of all ufa networks, UFADNA, with an update The first modern system in 2021.
Web football i99PRO online lottery เว็บบอล casino apply today for free 5000 bonus.
Kardinal Stick Siam - relx a great promotion. Express delivery in 3 hours.
Online Marketing Company By the way we can make your website. SEO Reach more customers directly to your business group. Grow your sales.
Online football betting i99club, one of the world's leading online gambling sites, เว็บแทงบอล provides the best prices in football betting.
Ufabet1688 online betting website ufabet is a 100% legal website with all licenses.
ufa football betting, casino, slots, lottery, direct website 1688, stable financial, 100% UFABET168.
Fan wreath shop with free delivery, พวงหรีด with pictures before-after sending with receipt.
Sticking to the COVID-19 situation: โควิด Arekorenavi.info.
Online Baccarat FOXZ24 Easy to apply, fast, บาคาร่า deposit-withdraw 10 seconds with the system.
Good work done and keep update more.I like your information's.
wordpress
blogger
youtube
ហ្គេមស្លត់
PGSLOTสามารถเข้าใช้งานเพื่อวางเดิมพันกับรูปแบบพนันออนไลน์ที่เลือกได้เลยทันที
JOKER123ที่มีระบบหลังบ้านไว้คอยดูแลได้อย่างดีที่สุด มีระบบที่เสถียร ไว้คอยบริการผู้เล่น
บาคาร่าทางเว็บไซต์ของเราแจกได้โดยไม่มีอั้นเลยทีเดียว สามารถเลือกรับโบนัสได้อย่างมากมาย
a good and fascinating post. Post regularly. Many thanks for sharing.
Oracle Recruiting Cloud Training
your work is very good really admirable for this piece This piece is really valuable. It is a work that explains deeply. helps to understand deeply
pgslot286
This article is very best for C programming students. Its very good information. I hope you will share more updates. Now it's time to avail FACE CLEANSER for more information.
I'm delighted to report that it's a fascinating post to read. Thank you for providing this information.
Diesel Generator for rent
Nice information, thanks for sharing this.
Graphic designing course in Chandigarh
Android training in Chandigarh
Very Useful Blog as it had high quality contents to deals with Carroll Condado DUI VA
Abogado Trafico Fairfax Va. Keep posting like this
Very useful information for job seekers. Really great post.
If interested in CCNA certification you can join CCNA online training with experts for one month.
a good article. You did a great job of explaining the details of the C Language . I must mention that you're doing an excellent job. continue posting
Snowflake Training
ServiceNow Training
Embedded training center in Chennai
best embedded training institute in Chennai
plc training center in Chennai
plc scada vfd dcs hmi training institute in Chennai
best final year Project center in Chennai
best final year Project center in Chennai
For the 1st point, no need to use Turbo C compiler, just add a layer of simplicity and efficiency to your coding experience. By forgoing the Turbo C compiler, you open the door to more modern and versatile alternatives, enhancing your development workflow. This adjustment eliminates unnecessary complexities, streamlining the coding process and allowing for greater compatibility with contemporary tools. Embracing this change ensures a smoother transition to current industry standards, fostering a more conducive environment for learning and innovation. In summary, opting out of the Turbo C compiler is a strategic move towards a more accessible and up-to-date coding practice.cuánto cuesta un divorcio de mutuo acuerdo en virginia
digital marketing training in trichy
Kochiva is a leading provider of education and training services, specializing in IT courses, foreign language courses, and career counseling. With a strong focus on quality education and student success, Kochiva offers a wide range of programs designed to meet the diverse needs of learners.
Most Difficult Languages in the world
Prepare for TEF Canada Exam
Best Online French Classes
Best Online German Classes in India
Study Nursing in Germany
MBBS in Germany
Study MS in Germany
LLM in Germany.
We provide a full range of Website Development, SEO, e-commerce, Web Design, Mobile apps, Web Application, and Digital Marketing in North Paravur, Kochi, Kerala.
https://www.auraweblabs.com/
Transform any space with these lively pink zebra blinds - perfect for a pop of color!
Do you know what is the NEWS Full Form ? News is crucial in today’s society because everybody would like to know what’s going on in their nation and worldwide, so they share every item of news they see on TV, on their phones, and in newspapers. What Is the FULL FORM of News, Interpretation, Meaning, and Utilizes will undoubtedly be reviewed here.
I’m glad you found the post helpful for your research! I'll be sure to share more information on the topic in the future.
node fullstack training in hyderabad
Very useful content ,Thank you
I am glad to see this content .Thank You Best Embedded Systems Course In Hyderabad
Post a Comment